SharePoint Online: Export Site Collection Administrators to CSV Report

Requirement: Get Site Collection Administrators Report for SharePoint Online.

PowerShell to Get Site Collection Administrators in SharePoint Online and Export to CSV:
Lets get site collection admins of all SharePoint Online sites and export them to a CSV report using PowerShell.
#Variables for processing
$AdminCenterURL = ""
Try {
    #Connect to SharePoint Online
    Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential)
    #Get all Site colections
    $Sites = Get-SPOSite -Limit ALL
    $SiteData = @()
    #Get Site Collection Administrators of Each site
    Foreach ($Site in $Sites)
        Write-host -f Yellow "Processing Site Collection:"$Site.URL
        #Get all Site Collection Administrators
        $SiteAdmins = Get-SPOUser -Site $Site.Url -Limit ALL | Where { $_.IsSiteAdmin -eq $True} | Select DisplayName, LoginName

        #Get Site Collection Details
        $SiteAdmins | ForEach-Object {
        $SiteData += New-Object PSObject -Property @{
                'Site Name' = $Site.Title
                'URL' = $Site.Url
                'Site Collection Admins' = $_.DisplayName + " ("+ $_.LoginName +"); "
    #Export the data to CSV
    $SiteData | Export-Csv $ReportOutput -NoTypeInformation
    Write-Host -f Green "Site Collection Admninistrators Data Exported to CSV!"
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
and the site collection administrators CSV report for all SharePoint Online site collections in the tenant:
sharepoint online get site collection administrators and export to CSV

1 comment:

  1. There's an error in your script where you set the variable for $AdminURL but call out $AdminCenterURL. Thx.


Please Login and comment to get your questions answered!

Powered by Blogger.