I am able to add O365 group as the SharePoint site visitor with this command
Add-SPOUser -Site 'https://xxx.sharepoint.com/sites/testsite01 -LoginName testgroup01@xxx.onmicrosoft.com -Group 'testsite01 Visitors'
I am going to add AAD group as the SharePoint site visitor, i have found the AAD Group GUID by this command:
Get-AzureADGroup -SearchString testgroup01 | Select DisplayName, ObjectID
Then i add the AAD Group with this command (I have confirmed the GUID is valid)
Add-SPOUser -Site 'https://xxx.sharepoint.com/sites/testsite01 -LoginName 'c:0t.c|tenant|af143a4a-f7f0-430c-b83b-c9b5dxxx2ef' -Group 'testsite01 Visitors'
The error message:
Add-SPOUser : Group cannot be found.
At line:1 char:1
+ Add-SPOUser -Site 'https://xxx.sharepoint.com/sites/testsite01
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-SPOUser], ServerException
+ FullyQualifiedErrorId : Microsoft.SharePoint.Client.ServerException,Microsoft.Online.SharePoint.PowerShell.AddSPOUser
Can anyone tell me what's wrong? thx !!
You may try PnP PowerShell to add an office 365 group to a SharePoint group.
#region Variables
$Username = "admin@xxx.onmicrosoft.com"
$Password = "password"
$siteURL = "https://xxx.sharepoint.com/sites/modernteam"
#endregion Variables
#region Credentials
[SecureString]$SecurePass = ConvertTo-SecureString $Password -AsPlainText -Force
[System.Management.Automation.PSCredential]$PSCredentials = New-Object System.Management.Automation.PSCredential($Username, $SecurePass)
#endregion Credentials
Connect-PnPOnline -Url $siteURL -Credentials $PSCredentials
Add-PnPUserToGroup -LoginName GroupLee@xxx.onmicrosoft.com -Identity 'modernteam Visitors'
Write-Host "---"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.