I have two scripts.
In the first script, I run through all of the sites and subsites in my tenant with PnP PowerShell, something like this:
$cred = Get-Credential
Connect-PnPOnline "https://tenant.sharepoint.com" -Credentials $cred
$SiteCollections = Get-PnPTenantSite
foreach($SiteCollection in $SiteCollections) {
Connect-PnPOnline -Url $SiteCollection.Url -Credentials $cred
$subwebs = Get-PnPSubWebs - Recurse
if ($subwebs) {
foreach($subweb in $subwebs) {
Connect-PnPOnline -Url $subweb.Url -Credentials $cred
}
}
}
In the second script, I would like to disable two options in SharePoint Online which cannot be changed with PnP Powershell. Something like this:
Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll'
$userName = "username"
$site = "siteUrl"
$pwd = Read-Host -Prompt "Please enter your password" -AsSecureString
$context = New-Object Microsoft.SharePoint.Client.ClientContext($site)
$cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName,$pwd)
$context.Credentials = $cred
# disabling "Allow members to share the site and individual files and folders"
$web = $context.Web
$context.Load($web)
$context.ExecuteQuery()
$web.MembersCanShare = $false
$web.Update()
# disabling "Allow members to invite others to the site members group"
$membersgroup = $context.Web.AssociatedMemberGroup
$context.Load($membersgroup)
$context.ExecuteQuery()
$membersgroup.AllowMembersEditMembership = $false
$membersgroup.Update()
$context.ExecuteQuery()
How can I combine the two approaches? What do you suggest?