Powershell Sharepoint递归添加权限以进行分组

时间:2018-10-19 16:21:03

标签: powershell sharepoint

我有一个脚本,该脚本将在Sharepoint网站中的子网站之间循环,如果该网站具有唯一权限,我们需要向目标组添加“完全控制”权限。我遇到了一个问题,因为当我运行脚本时,目标组未出现在Sahrepoint网站权限中。该组存在于“人员和组”中,但是当我进入“网站权限”时,该组不存在。我还尝试检查目标组的角色,但收到错误消息“找不到权限级别。为什么脚本无法正常运行? 该脚本以。\ subsites.ps1 https:somewebsite.sharepoint.com/sites/TargetSite目标组的身份运行。我有三个vairbles targetGroups1-3,它们的组名始终是三个单词。

#gets website URL from user
$site = $Args[0]
$targetGroup1 = $Args[1]
$targetGroup2 = $Args[2]
$targetGroup3 = $Args[3]
$group = $targetGroup1 +" "+ $targetGroup2 + " "+ $targetGroup3
#Using PnP to connect to sharepoint
Connect-PnPOnline -Url $site -UseWebLogin
#this will get subsites from sharepoint
$currentSubwebs = Get-PnPSubwebs -Recurse -Includes HasUniqueRoleAssignments
#loops through each subsite 
foreach ($currentSubweb in $currentSubWebs) {
$subWebTitle = $currentSubWeb.Title

#Returns true for unique permissions, false for inherited permissions  
if ($currentSubweb.HasUniqueRoleAssignments -eq "True") {  
Write-Host $subWebTitle -ForegroundColor Red
$subSiteURL = $currentSubweb.Url
Write-Host $subSiteURL -ForegroundColor Green            
Write-Host $currentSubweb.Title 'has unique permissions'
#Add permissions to the targeted group
Set-PnPGroupPermissions -Identity $group -AddRole 'Full Control'
#check to see role of targeted group
Get-PnPGroupPermissions -Identity $group 
#checking to see if the arguments are passed 
Write-Host $site $group

#write sites that have their permissions changed to log file 
$permissionChanged=$subSiteURL
$permissionChanged|Out-File -FilePath C:\Users\crace1\Desktop\Logs\permissionlog.txt -Append
Write-Host '----------------------------------------'
   }         
}

0 个答案:

没有答案