使用pnpPowershel的Sharepoint在线列表和项目级别权限

时间:2019-03-14 07:42:50

标签: sharepoint powershell-v4.0

我正在尝试使用以下来自引用的脚本在我们的SharePoint在线网站上获取网站/列表/库/项目/子网站级别权限/唯一权限:

https://social.technet.microsoft.com/Forums/forefront/en-US/77a8e9ef-56a5-47e4-9b54-209f37687013/sharepoint-online-subsite-permissions-list-credenstials-promt?forum=onlineservicessharepoint-被MichaelIT02标记为答案

但是,我仅使用上述代码在PNP Powershell中获得站点/子站点级别的权限。我尝试使用PNP中的脚本来获取列表和库许可/唯一许可,但找不到想法。如果有人可以帮助我扩展相同的代码,将不胜感激。

预先感谢!

请检查以下代码: 在这里,我无法获得项目级别的权限。

$siteUrl="https://TestSite.sharepoint.com/sites/TeamsiteSample"
$outputFile= "C:\Users\123\Desktop\SiteAndSubsitePermission.csv" 
$username="xyz@xyz.onmicrosoft.com"
$password="xyz@12345"
$encpassword = convertto-securestring -String $password -AsPlainText -Force
$credential = new-object -typename System.Management.Automation.PSCredential - 
argumentlist $username, $encpassword

Connect-PnPOnline -Url $siteUrl -Credentials $credential

# output file name and location
"List Title `t Title `t PrincipalType `t Permission `t GivenThrough" | Out-File 
$outputFile -Append

#`t LoginName
# get document library
$library = Get-PnpList -Includes RoleAssignments
#-Identity $libraryName -Includes RoleAssignments

foreach($libraryList in $library)
{

# get all the users and groups who has access
$roleAssignment = $libraryList.RoleAssignments
foreach ($roleAssignment in $roleAssignment)
{
Get-PnPProperty -ClientObject $roleAssignment -Property RoleDefinitionBindings, 
Member

$ListTitle = $libraryList.title
$loginName = $roleAssignment.Member.LoginName
$title = $roleAssignment.Member.Title
$principalType = $roleAssignment.Member.PrincipalType
$givenThrough = ""
$permissionLevel = ""

# loop through permission levels assigned to specific user/group
foreach ($roleDefinition in $roleAssignment.RoleDefinitionBindings){
    $PermissionLevel += $RoleDefinition.Name + ";"
}
$givenThrough = "Given directly"
"$($ListTitle) `t $($title)  `t $($principalType) `t $($permissionLevel) `t 
$($givenThrough)" | Out-File $outputFile -Append

#`t $($loginName)

# if principal is SharePoint group -> get SharePoint group members
#if ($roleAssignment.Member.PrincipalType.ToString() -eq "SharePointGroup")
#  {
#    $givenThrough = $roleAssignment.Member.Title.ToString()

#    $groupMembers = Get-PnpGroupMembers -Identity $roleAssignment.Member.LoginName
 #   foreach ($member in $groupMembers)
#    {
#        "$($member.Title) `t $($member.LoginName) `t $($member.PrincipalType) `t 
 $($permissionLevel) `t $($title) `t $($ListTitle)" | Out-File $outputFile -Append
#    }
 # }
 }
 }


$subwebs=Get-PNPSubWebs 
foreach($subweb in $subwebs) 
{ 
#Connect-PNPonline -Url $siteUrl -Credentials $credential
#Write-Host $subweb.Url 
$groups=Get-PNPGroup 
foreach($group in $groups) 
{ 
#$DLGP = "" | Select "SiteUrl","GroupName","Permission" 

$sPerm=Get-PNPGroupPermissions -Identity $group.loginname -ErrorAction 
SilentlyContinue |Where-Object {$_.Hidden -like "False"} 
if ($sPerm -ne $null) 
{ 
$SiteUrl=$subwebs.title 
$GroupName=$group.loginname 
$Permission=$sPerm.Name 
#Test columns
"$($SiteUrl) `t $($GroupName)  `t $($Permission)" | Out-File $outputFile -Append
} 
} 
Write-Host $subweb.Url "permission fetched!" } 

0 个答案:

没有答案