Monday, June 6, 2016

SharePoint Online: PowerShell to Get Site Collection Administrators

How to Get site collection administrators in SharePoint Online?
If you want to get all site collection administrators,

  • Click on Site Settings Gear, select Site Settings
  • In Site Settings page, click on "Site Collection Administrators" link under "Users and Permission" group.
  • This page gives you the list of site collection administrators on the particular site collection.
    sharepoint online get site collection admin powershell
PowerShell online: PowerShell to get site collection administrator
You can use the PowerShell cmdlet Get-SPOUser along with the filter IsSiteAdmin property to get the list of Site collection administrators of the given site collection.
#Variables for processing
$AdminURL = "https://Crescent-admin.sharepoint.com/"
$AdminName = "SPAdmin@Crescent.com"
$SiteCollURL="https://Crescent.sharepoint.com/sites/sales"
 
#User Names Password to connect 
$Password = Read-host -assecurestring "Enter Password for $AdminName" 
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName, $Password

#Connect to SharePoint Online
Connect-SPOService -url $AdminURL -credential $Credential

#Get the Site colection
$SiteColl = Get-SPOSite $SiteCollURL
    
#Get all Site Collection Administrators
$SiteAdmins = Get-SPOUser -Site $SiteCollURL -Limit ALL | Where { $_.IsSiteAdmin -eq $True}
foreach($Admin in $SiteAdmins)
{
    Write-host $Admin.LoginName        
}

PowerShell to get site collection Administrators of all site collections in SharePoint online:
Lets add some error handling and get the list of site collection administrators from all site collections.
#Variables for processing
$AdminURL = "https://Crescent-admin.sharepoint.com/"
$AdminName = "spadmin@Crescent.com"
 
#User Names Password to connect 
$Password = Read-host -assecurestring "Enter Password for $AdminName" 
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $AdminName, $Password

Try {
    #Connect to SharePoint Online
    Connect-SPOService -url $AdminURL -credential $Credential

    #Get all Site colections
    $Sites = Get-SPOSite -Limit ALL

    Foreach ($Site in $Sites)
    {
        Write-host $Site.URL
    
        #Get all Site Collection Administrators
        $SiteAdmins = Get-SPOUser -Site $Site.Url -Limit ALL | Where { $_.IsSiteAdmin -eq $True}
        foreach($Admin in $SiteAdmins)
        {
            Write-host $Admin.LoginName        
        }
    }
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!


You might also like:

Related Posts Plugin for WordPress, Blogger...