kwizcom banner advertisement

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
$AdminURL = "https://Crescenttech-admin.sharepoint.com/"
$ReportOutput="C:\Temp\SiteCollectionAdmins.csv"
 
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 +"); "
                }
        }
    }
    $SiteData 
    #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
SharePoint Online: Export Site Collection Administrators to CSV Report SharePoint Online: Export Site Collection Administrators to CSV Report Reviewed by Salaudeen Rajack on January 19, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.