通过 PowerShell 向组授予 SharePoint Online 文件夹权限
Grant SharePoint Online Folder Permission to Group via PowerShell
我可以向 SharePoint Online 文件夹中的用户授予权限,但无法向组授予权限,这是代码和结果
$folder = Get-PnPFolder -URL "https://xxx.sharepoint.com/sites/test/Shared Documents/folderA"
$Role = Contribute
授予用户作品权限
Set-PnPfolderPermission -list "Documents" -identity $folder -User "testuser01@xxx.onmicrosoft.com" -AddRole $Role
授予组权限失败
Set-PnPfolderPermission -list "Documents" -identity $folder -Group "Test-Group" -AddRole $Role
结果
Set-PnPfolderPermission : Group cannot be found.
At line:1 char:1
+ Set-PnPfolderPermission -list "Documents" -identity $folder -Group "T ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Set-PnPFolderPermission], ServerException
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Files.SetFolderPermission
自己找到答案,用-User groupname@xxx.onmicrosoft.com将组添加到文件夹中。
所以 -Group 在这个命令中是无效的,组名应该使用 O365 组的电子邮件地址(例如 Test-Group@xxx.onmicrosoft.com)
Set-PnPfolderPermission -list "Documents" -identity $folder -User "Test-Group@xxx.onmicrosoft.com" -AddRole $Role
也支持 AAD 组(例如 AADGroup01)
Set-PnPfolderPermission -list "Documents" -identity $folder -User "AADGroup01" -AddRole $Role
我可以向 SharePoint Online 文件夹中的用户授予权限,但无法向组授予权限,这是代码和结果
$folder = Get-PnPFolder -URL "https://xxx.sharepoint.com/sites/test/Shared Documents/folderA"
$Role = Contribute
授予用户作品权限
Set-PnPfolderPermission -list "Documents" -identity $folder -User "testuser01@xxx.onmicrosoft.com" -AddRole $Role
授予组权限失败
Set-PnPfolderPermission -list "Documents" -identity $folder -Group "Test-Group" -AddRole $Role
结果
Set-PnPfolderPermission : Group cannot be found.
At line:1 char:1
+ Set-PnPfolderPermission -list "Documents" -identity $folder -Group "T ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Set-PnPFolderPermission], ServerException
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Files.SetFolderPermission
自己找到答案,用-User groupname@xxx.onmicrosoft.com将组添加到文件夹中。 所以 -Group 在这个命令中是无效的,组名应该使用 O365 组的电子邮件地址(例如 Test-Group@xxx.onmicrosoft.com)
Set-PnPfolderPermission -list "Documents" -identity $folder -User "Test-Group@xxx.onmicrosoft.com" -AddRole $Role
也支持 AAD 组(例如 AADGroup01)
Set-PnPfolderPermission -list "Documents" -identity $folder -User "AADGroup01" -AddRole $Role