I am trying to remove a cached user account added in more than 18000 sites. for that I have been trying below PNP script:
$displayName = "DisplayNameOfAccountThatNeedTobeRemoved"
Get-PnPTenantSite | ForEach-Object {
$site = $_
Write-Host "Processing $($site.Url)..."
Connect-PnPOnline $site.Url -Credentials $creds
Get-PnPUser | ? Title -like $displayName | Remove-PnPSiteCollectionAdmin
}
But it is giving me an error "Access denied. You do not have permission to perform this action or access this resource."
I have also tried Remove-SPOUSer cmdlet too but it is giving me same error message.
I cannot add my account as a site collection admin on all the sites due to compliance and efficiency purposes. I do have SharePoint admin rights though.