Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to execute PnP script, getting error for cmd line Get-PnPUser -WithRightsAssigned | ? Title -eq "xxx@yyy.com" #979

Open
sundar399 opened this issue Feb 6, 2024 · 0 comments

Comments

@sundar399
Copy link

Hello team,

We are trying to execute a PnP script to get specific users (generic, bot accounts etc.,) permission present in all sharepoint sites in the tenant and remove those users permission also. When we run the script to get the user permission for the sites we are getting the below error,
"Get-PnPUser : The remote server returned an error: (403) Forbidden." (shared screenshot for full error)

We are sharing the script, where we try to get the user permission here,

Connect-PnPOnline -Url "tenant-url"
Connect-SpoService -Url "tenant-url"
$siteCollections = Get-PnPTenantSite

foreach($site in $siteCollections){
     Connect-PnPOnline -Url $site.Url -UseWebLogin
    
     Set-SPOUser -Site $site.Url -LoginName AdminLoginName -IsSiteCollectionAdmin $true

     write $site.Url Get-PnPUser -WithRightsAssigned | ? Title -eq "xxx@yyy.com"

    Set-SPOUser -Site $site.Url -LoginName AdminLoginName -IsSiteCollectionAdmin $false
    
    Disconnect-PnPOnline
}

PnP-error msg

FYI, our final result was to remove the specific users permission in all the sites in the SharePoint tenant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant