kwizcom banner advertisement

SharePoint Online: PowerShell to Get Site Collection Administrators

SharePoint site collection administrators possess full control to the entire site collection - including top-level site, subsites and all lists and libraries in the site collection. Each SharePoint 2016 site collection can have its own Site Collection Administrators, Typically assigned during the time of site collection is creation by SharePoint Online administrators through SharePoint Online Admin Center site as Primary and secondary site collection owners. Additional site collection administrators can be added/removed through site collection settings page.

Site collection administrators have same access rights as same as primary or secondary site owners but the only difference is: E-mail notifications! Primary and secondary site collection administrators are those who'll be getting Email notifications such as site collection storage limit warning Emails.

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
}
SharePoint Online: PowerShell to Get Site Collection Administrators SharePoint Online: PowerShell to Get Site Collection Administrators Reviewed by Salaudeen Rajack on June 06, 2016 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.