How can I retrieve site permissions on a site or subsite using PnP PowerShell?

Example: https://$orgName.sharepoint.com/sites/IT/Atlas

Via the UI: Site settings > Site Permissions

With PnP PowerShell, the following didn't work for me:

Connect-PnPOnline -Url "https://$orgName.sharepoint.com/sites/IT/Atlas" -Credentials $userCredential
$web = Get-PnPWeb -Includes RoleAssignments

[Edit] The above code actually seems to work, as $web.RoleAssignments.Count returns 5. My issue is that I don't know how to take it from here, to enumerate the 5 members and their roles.

RoleAssignments.Member returns 5 items but I can't figure out how to get the names and roles.

RoleAssignments.Groups only returns the SharePoint groups.

2 Answers 2


The question has been answered on Microsoft Tech Community.

Here is the accepted answer:

$cred = get-credential
Connect-PnPOnline -Url "https://$orgname.sharepoint.com" -Credentials $cred
$web = Get-PnPWeb -Includes RoleAssignments
foreach($ra in $web.RoleAssignments) {
    $member = $ra.Member
    $loginName = get-pnpproperty -ClientObject $member -Property LoginName
    $rolebindings = get-pnpproperty -ClientObject $ra -Property RoleDefinitionBindings
    write-host "$($loginName) - $($rolebindings.Name)"

The following PowerShell code snippet assits to retrieve the site properties:

$siteurl = "https://abc.sharepoint.com"
Connect-SPOnline -Url $siteurl
$ctx = Get-SPOContext

Get Current Context Site (Root)

function RetrieveSite(){
$web = Get-SPOWeb
Write-Host "Title : " $web.Title
Write-Host "Description : " $web.Description
Write-Host "URL : " $web.Url

Get Sub Site

function RetrieveSubSite(){
$web = Get-SPOWeb "PnPSite1"
Write-Host "Title : " $web.Title
Write-Host "Description : " $web.Description
Write-Host "URL : " $web.Url
RetrieveSite #Get Current Context Site (Root)
RetrieveSubSite #Get Sub Site

Please refer to the below link

Use powershell to retrieve all subsites for sharepoint online

Hope it helps!

  • 1
    This doesn't answer the question for how to retrieve the permissions for a site.
    – moe
    Dec 29, 2017 at 13:22
  • Thanks for your reply. My question is specifically about fixing the code I posted (use of PnP), and retrieving site permissions. Everything else (title, description, URL) works as intended.
    – Christophe
    Dec 29, 2017 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.