Get list of Site Collection Admins (SCA) using PowerShell

Requirement

Generate a list of SCAs across all your SharePoint site collections.

Solution

function Get-SCA {
param($site)
$link = $site+"/_layouts/mngsiteadmin.aspx"
 
$result = Invoke-WebRequest $link -UseDefaultCredentials
 
$value = $result.AllElements |
Where id -eq "ctl00_PlaceHolderMain_ctl00_PeopleEditorAdmins_OriginalEntities" |
Select value
$value = $value.value.split(">") | where { $_ -match "displaytext" }
$value = $value.split("`"") | where { $_ -notmatch "=" -and $_ -notmatch "ct" -and $_ -notmatch "true" -and $_ }
#$value = $value -join ' '
return $value
}

To use the above function:
Syntax: Get-SCA -site <site collection url>

You can then use this function within a loop to iterate through all your site collections to generate a list of SCAs.

 

Tags: ,

One Response to “Get list of Site Collection Admins (SCA) using PowerShell”

  1. Rick Kushner September 15, 2016 at 11:41 pm #

    I took aInvoke-WebRequest out of the script, and I am unable to authenticate. I am connected to my SharePoint tenant, so I can confirm the url, my username & my password. But I am able to authenticate with connect-sposervice (same credentials) and verify that connection using Get-SPOSite!

Leave a Reply

%d bloggers like this: