[BUG]Remove-PnPUser throws ServerUnauthorizedAccessException for some sites
Reporting an Issue or Missing Feature
For a few, seemingly random sites, the Remove-PnPUser cmdlet reports ServerUnauthorizedAccessException. I am connecting with clientid + secret, went through about 2000 sites, about 15 throws this error. The command works on rest of the sites fine, the user is removed.
Expected behavior
The command should remove the given user.
Actual behavior
for sime sites, the following error is reported: Remove-PnPUser : Attempted to perform an unauthorized operation. At line:27 char:1
- Remove-PnPUser -Identity "xxxxx" -Co ...
-
+ CategoryInfo : WriteError: (:) [Remove-PnPUser], ServerUnauthorizedAccessException + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Principals.RemoveUser
Steps to reproduce behavior
Please include complete script or code samples in-line or linked from gists '' Connect-PnPOnline -Url $_ -ClientSecret $clientsecret -ClientId $clientid -WarningAction Ignore '' Remove-PnPUser -Identity $usertoremove -Confirm:$false
What is the version of the Cmdlet module you are running?
1.11.0
Which operating system/environment are you running PnP PowerShell on?
- [x] Windows
- [ ] Linux
- [ ] MacOS
- [ ] Azure Cloud Shell
- [ ] Azure Functions
- [ ] Other : please specify
On what kind of sites does the command fail? Are those special sites or random team / communication sites? Are those sites perhaps locked ? ( Read only )?
Looks like some configuration issue which is preventing you from removing the user. Moving this to discussion as there is no issue with the cmdlet itself which works as expected.