$credentail = Import-Clixml D:\cred.xml
$siteurl = "https://metho.sharepoint.com/sites/EducationandHumanities41"
$access = "Read"
$folders = Import-csv "C:\Users\metho\Desktop\sharepoint_Permissions.csv"
Connect-PnPOnline -Url $siteurl -Credentials $credentail
Foreach ($entry in $folders) {
$ListName = $entry.'Assoc Dean Area Name'
$foldername = $entry.'Curriculum Area Name'
$foldername2 = $entry.'Course Title'
$foldername3 = $entry.c16
$Nameofthefolder = $entry.currTeamName
$emailAddress= $entry.facultyHeademail
$UserOne = $entry.DeanName
#Get-PnPFolder -Url $Listname
$ListitemID = Get-PnPListItem -List $ListName
#$listItem = Get-PnPListItem -List $Listname -Query "<View><Query><Where><Eq><FieldRef Name='Id'/><Value Type='Text'>$ListName</Value></Eq></Where></Query></View>"
Set-PnPListItemPermission -List $Listname -Identity $ListitemID -User $UserOne -AddRole $access
}
我正在努力将权限应用于SharePoint“文档库”下的所有子文件夹。我正在用子文件夹的ID挣扎(我认为这是问题)。如果我手动添加ID,则会将权限应用于文件夹的特定ID,但我希望将其应用于文档库下的所有子文件夹。
Set-PnPListItemPermission : Cannot convert 'System.Object[]' to the type 'SharePointPnP.PowerShell.Commands.Base.PipeBinds.ListItemPipeBind' required by parameter 'Identity'. Specified method is not supported.
At line:31 char:53
+ ... t-PnPListItemPermission -List $Listname -Identity $ListitemID -User $ ...
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-PnPListItemPermission], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,SharePointPnP.PowerShell.Commands.Lists.SetListItemPermission
答案 0 :(得分:1)
命令Get-PnPListItem
将从列表中检索所有列表项。根据您的要求,您需要遍历文档库中的每个文件夹并应用权限。
这是我的演示:
$listname="test"
$SiteURL = "https://tenant.sharepoint.com/sites/michael"
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
$ParentFolderURL = "/test" #Site Relative Path of the document Library
$UserAccount = "michael@domain.com"
$AllFolders= Get-PnPFolderItem -ItemType Folder -FolderSiteRelativeUrl $ParentFolderURL | Where {($_.Name -ne "Forms") -and (-Not($_.Name.StartsWith("_")))}
ForEach($Folder in $AllFolders) {
#Grant Contribute permissions to the Folder
Set-PnPListItemPermission -List $ListName -Identity $Folder.ListItemAllFields -User $UserAccount -AddRole 'Read'
}