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.
- # Input Parameters
- $credentials=Get-Credential
- $URL="https://c986.sharepoint.com"
-
- # Connect to SharePoint Online
- Connect-PnPOnline -Url $URL -Credentials $credentials
-
- # Get the site collections
- $siteColl=Get-PnPTenantSite
-
- # Loop through the site collections
- foreach($site in $siteColl)
- {
- write-host -ForegroundColor Green "Getting SCA from site: " $site.Url
- Connect-PnPOnline -Url $site.Url -Credentials $credentials
-
- # Get the site collection administrators
- $scaColl=Get-PnPSiteCollectionAdmin
- foreach($sca in $scaColl)
- {
- $sca
- }
- }
Open PowerShell window and run the following command.
folderlocation – GetSCA.ps1 file location
Run the following command
Thus, in this blog, you saw how to get all site collection administrators from SharePoint Online Site Collections using PnP PowerShell.