Get Site collection Administrators for SharePoint Online using PowerShell

SharePoint Online sites can have thousands of users.  There are times when people are asked to get site collection admins using SharePoint Online Management Shell or Get-SPOUser cmdlet with Where $_.IsSiteAdmin.  This will result in timeout if there are lot of users on the site.  Instead I decided to use a different approach.  First get all the users from site into a CSV and then make the check. 

image

$Creds = Get-Credentials

$site = ‘https://sharepoint-admin.sharepoint.com’
Connect-SPOService -Url $site -Credential $Creds

$AllUsers = Get-SPOUser -Site https://site.sharepoint.com -Limit all | select DisplayName, LoginName,IsSiteAdmin
$AllUsers | Export-Csv -Path C:\temp\allusers.csv -NoTypeInformation -Force
$Data = Import-Csv C:\temp\allusers.csv
foreach($aUser in $Data)
{
  if($aUser.IsSiteAdmin -eq “True”)
  {
    Write-Host $aUser.DisplayName $aUser.LoginName
  }
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s