In this blog, you will see how to get all site collection administrators from SharePoint Online Site Collections from your tenant using PnP PowerShell.

You can download the setup files from the releases section of the PnP PowerShell repository.

Copy the below script and paste it in a Notepad. Save the file as GetSCA.ps1.

  1. # Input Parameters
  2. $credentials=Get-Credential
  3. $URL="https://c986.sharepoint.com"
  4. # Connect to SharePoint Online
  5. Connect-PnPOnline -Url $URL -Credentials $credentials
  6. # Get the site collections
  7. $siteColl=Get-PnPTenantSite
  8. # Loop through the site collections
  9. foreach($site in $siteColl)
  10. {
  11. write-host -ForegroundColor Green "Getting SCA from site: " $site.Url
  12. Connect-PnPOnline -Url $site.Url -Credentials $credentials
  13. # Get the site collection administrators
  14. $scaColl=Get-PnPSiteCollectionAdmin
  15. foreach($sca in $scaColl)
  16. {
  17. $sca
  18. }
  19. }

Open PowerShell window and run the following command.

  1. >cd "<folderlocation>"

folderlocation – GetSCA.ps1 file location

Run the following command

  1. >.\GetSCA.ps1

Reference - Get-PnPSiteCollectionAdmin

Thus, in this blog, you saw how to get all site collection administrators from SharePoint Online Site Collections using PnP PowerShell.