We used PowerShell for removing users from SCA (Site Collection Administrator). You have to add all sites in .CSV file (mention full path of .csv in $csvPath). PowerShell code will read the .csv file and it will one by one connect to all sites using PnP. You have to add all users in the $allEmailIDs array. $allErrorSites will print all error sites.
The error will be,
  1. If you do not have access to that site.
  2. If the email id is not valid.
Use below code in PowerShell,
  1. $csvPath = ".CSV FILE PATH"
  2. $allSitesUrls = Get - Content $csvPath
  3. $allEmailIDs = @("EMAIL ID - 1", "EMAIL ID - 2")
  4. $allErrorSites = @()
  5. try {
  6. ForEach($singleSiteUrl in $allSitesUrls) {
  7. : InnerLoop ForEach($emailID in $allEmailIDs) {
  8. try {
  9. Write - Host "Start Process for : $($singleSiteUrl)";
  10. Connect - PnPOnline $singleSiteUrl - UseWebLogin
  11. Remove - PnPSiteCollectionAdmin - Owners $emailID
  12. Write - Host "SCA access has been removed of : $($emailID) from site $($singleSiteUrl)";
  13. } catch {
  14. #Add the object with property to an Array
  15. $allErrorSites += $singleSiteUrl;
  16. [string] $FuncName = $MyInvocation.MyCommand.Name;
  17. Write - Host - Message $_ - FunctionName $FuncName;
  18. }
  19. }
  20. }
  21. #It will print all sites which got error
  22. Write - host - f Red $allErrorSites;
  23. } catch {
  24. [string] $FuncName = $MyInvocation.MyCommand.Name;
  25. Write - Host - Message $_ - FunctionName $FuncName;
  26. }