Thursday, August 8, 2013

Site Collection Administrators Report for All SharePoint Sites

I just had to generate a report to find SharePoint site collection administrators and see who are all assigned with Site collection administrator rights on various site collection in entire SharePoint Farm.

Sure, Lets use PowerShell in SharePoint to get site collection administrator programmatically. This script iterates through all site collections in all web applications to list site collection administrators.

PowerShell Script to Get All Site Collection Administrators (I've made it compatible with SharePoint 2007)

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

#Get the Farm
$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local

#Get All Web Applications
$farmWebServices = $farm.Services | where -FilterScript {$_.GetType() -eq [Microsoft.SharePoint.Administration.SPWebService]}
foreach ($farmWebService in $farmWebServices) {
 #Loop through Each web applicatoin
  foreach ($webApplication in $farmWebService.WebApplications) {
    #Loop through each site collection
    foreach ($site in $webApplication.Sites)
    {
   $Admins=""
   #Get all Site Collection Administrators
      foreach ($siteCollAdmin in $site.RootWeb.SiteAdministrators)
      {
        $Admins+= $siteCollAdmin.LoginName +";"
      }
        Write-Host "Site URL: " $site.RootWeb.Url " - Site Collection Admins: " $Admins "`n"
        $site.Dispose()
    }
  }
}
By the way, It works on SharePoint 2010 and SharePoint 2013 as well.



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:

2 comments :

  1. Is there a similar command to get a report out of Sharepoint Online?

    ReplyDelete
  2. Hello
    do we have any script to get a report out of SharePoint Online?

    ReplyDelete

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...