How To Get All Site Collection Administrators From SharePoint Online Site Collections Using PnP PowerShell

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.     
  5. Connect to SharePoint Online   
  6. Connect-PnPOnline -Url $URL -Credentials $credentials  
  7.   
  8. # Get the site collections  
  9. $siteColl=Get-PnPTenantSite  
  10.   
  11. # Loop through the site collections  
  12. foreach($site in $siteColl)  
  13. {  
  14.     write-host -ForegroundColor Green "Getting SCA from site: " $site.Url  
  15.     Connect-PnPOnline -Url $site.Url -Credentials $credentials  
  16.   
  17.     # Get the site collection administrators  
  18.     $scaColl=Get-PnPSiteCollectionAdmin   
  19.     foreach($sca in $scaColl)  
  20.     {          
  21.         $sca  
  22.     }  
  23. }  

Open PowerShell window and run the following command.

  1. >cd "<folderlocation>"  

folderlocation – GetSCA.ps1 file location

Run the following command

  1. >.\GetSCA.ps1  

 

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