Forum Discussion
Dec 14, 2017
PowerShell script to get the list of all the SharePoint site collection administrators in the tenant
Hi ,
Can someone help me with a Powershell script that helps in fetching the list of all the site collection administrators as well as the corresponding Site URL .I tried the below mentioned two ...
Manidurai Mohanamariappan
Dec 14, 2017Iron Contributor
you can try this modified script
$Creds = Get-Credential
$site = ‘https://tenant-admin.sharepoint.com’
Connect-SPOService -Url $site -Credential $Creds
$AllSites= Get-SPOSite -Limit All
$users = @();
foreach ($Allsite in $AllSites)
{
$AllUsers = Get-SPOUser -Site $AllSite.Url -Limit all | select DisplayName, LoginName,IsSiteAdmin
$users+=$AllUsers
$AllUsers = $null
#Write-Host $AllSite.Url" completed"
}
$users | Export-Csv -Path "C:\Users\Desktop\allusers.csv" -NoTypeInformation -Force
$Data = Import-Csv "C:\Users\Desktop\allusers.csv"
foreach($aUser in $Data)
{
if($aUser.IsSiteAdmin -eq “True”)
{
Write-Host $aUser.DisplayName $aUser.LoginName
}
}