Вопрос

In SPO we have a couple of sites that lack a default group for the "Allow members to share this site and individual files and folders".

enter image description here

I'm trying to set a SharePoint security group named "OOTB Visitors" as the default group for this through PowerShell.

Through the GUI it's easily done by going into the group choosing:

enter image description here

In PowerShell I found a method for the web named .CreateDefaultAssociatedGroups()

However, I can't get it to work. I don't get an error message but it also doesn't change anything.

Any idea what I'm missing?

Here's my code:

$ctx = Get-PnPContext
$web.CreateDefaultAssociatedGroups('Owners', $null, 'OOTB Visitors')
$web.Update()
$ctx.ExecuteQuery()
Это было полезно?

Решение 2

I believe to have fixed it. I noticed that the first argument passed into CreateDefaultAssociatedGroups has to be a site owner present in the user information list for that site. Retrieved one via Get-PnpUser, stored the result in an object and passed it as the first argument. Note however that if the groups are already present no duplicates will be created.

Другие советы

Please try the following code:

Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"  
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"  

$siteURL = "https://xxx.sharepoint.com/sites/wendy2"  
$userId = "xxx@xxx.onmicrosoft.com"  
$pwd = Read-Host -Prompt "Enter password" -AsSecureString  
$creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId, $pwd)  
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)  
$ctx.credentials = $creds  
try{  
    $web = $ctx.web  
    $ctx.load($web) 
    $ctx.executeQuery()  
    $web.CreateDefaultAssociatedGroups('xxx', $null, 'xxx')
    $web.Update()
    $ctx.executeQuery()
}  
catch{  
    write-host "$($_.Exception.Message)" -foregroundcolor red  
} 
Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top