Unable to execute PnP script, getting error for cmd line Get-PnPUser -WithRightsAssigned | ? Title -eq "xxx@yyy.com"
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 259
- Forks
- 161
- Avg merge
- 10h 33m
- Merged PRs (30d)
- 1
Description
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
}
FYI, our final result was to remove the specific users permission in all the sites in the SharePoint tenant.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided PowerShell sequence, especially Connect-PnPOnline, Set-SPOUser, and Get-PnPUser -WithRightsAssigned, and reproduce the 403 response against a representative site. Review the full error and authentication context to determine whether the command can enumerate users; document the required change or confirmed limitation as the completed outcome.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- authorization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100