Home Contact

The Frog Pond of Technology

Ripples of Knowledge for SharePoint and Other .Net Technologies

News

My blog has moved to WordPress at BrianTJackett.com. Any pages will automatically redirect to the new address in 7 seconds. Please excuse an issues during this migration.

 Subscribe to this blog


About Me

Name:
Brian T. Jackett
Location:
Columbus, OH
Company:
Microsoft

Find me on...

Tag Cloud


Archives

Post Categories

Syndication:

PowerShell Script To Display All SharePoint Site Collection Administrators In Web Application

    In this post I present a script that will display all of the site collection administrators for a given web application.  This script will work for SharePoint 2007 or 2010 as it uses the object model rather than the new SharePoint 2010 commandlets.  Special thanks to Tasha Scott (Twitter) for posting a request for this script.  It took less than 15 minutes to come up with and formalize.

tweet1

Solution

    The solution is fairly straight forward.  First you grab a reference to a site collection.  Get the web application from that.  Then loop through all of the site collections within the web application.  For each site collection iterate over the SiteAdministrators property for the RootWeb.  Then write out the site url and admin display names.  The script below is the condensed version, but the version on the Script Repository is a bit fleshed out.

 

Click here for link to TechNet Script Repository full version

$siteUrl = Read-Host "Enter Site URL"
 
$rootSite = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$spWebApp = $rootSite.WebApplication
 
foreach($site in $spWebApp.Sites)
{
    foreach($siteAdmin in $site.RootWeb.SiteAdministrators)
    {
        Write-Host "$($siteAdmin.ParentWeb.Url) - $($siteAdmin.DisplayName)"
    }
    $site.Dispose()
}
$rootSite.Dispose()

 

Conclusion

    As in past times a friend on Twitter has run into a roadblock, requested help, and I was able to come up with a PowerShell script in a short amount of time to solve the problem.  I really enjoy the SharePoint community and how it can band together when situations like this arise.  Hopefully you’ll use this script and share some of your own in the future.  For now enjoy documenting the site collection admins in your farm.

 

      -Frog Out


Friday, March 25, 2011 3:40 PM

Feedback

# re: PowerShell Script To Display All SharePoint Site Collection Administrators In Web Application

This was awesome. I've said it before, but the SP community on Twitter is the best. THANK YOU! :-D 3/25/2011 4:22 PM | Tasha

# re: PowerShell Script To Display All SharePoint Site Collection Administrators In Web Application

Also, I can at this point attest to the successfulness of this script- we were able to get exactly what we needed with only one minor change-
From this:
Write-Host "$($siteAdmin.ParentWeb.Url) - $($siteAdmin.DisplayName)"
To this:
Write-Host "$($siteAdmin.ParentWeb.Url) - $($siteAdmin.Name)"

With DisplayName we were getting blank/null values; prolly something in our setup.

Thanks again! At some point I hope I'm able to give you a hug! 3/30/2011 4:03 PM | Tasha

# re: PowerShell Script To Display All SharePoint Site Collection Administrators In Web Application

Thanks for the script. Very useful. Cheers. 6/29/2011 5:07 AM | Rich Warner

# re: PowerShell Script To Display All SharePoint Site Collection Administrators In Web Application

Any way to grab all WebAps and Site collections from a farm without providing anything so that we can report all stale sites on a MOSS 2007 farm? The below link is does this but you have to supply each site collection url. Thanks.

http://ecsdukece.wordpress.com/2011/06/30/using-powershell-to-find-stale-sharepoint-sites/#comment-13 7/20/2011 3:30 PM | jcnet

# re: PowerShell Script To Display All SharePoint Site Collection Administrators In Web Application

jcnet,

If you follow this link to another post I wrote it goes through the process of enumerating all web apps, site collections, and sites within a farm. All you need to do is supply one url for the farm you want to hit. Works in 2007 and 2010. Let me know if that works or not.

http://geekswithblogs.net/bjackett/archive/2009/04/24/the-power-of-powershell-and-sharepoint-enumerating-sharepoint-permissions-and.aspx

7/25/2011 8:59 AM | Brian T Jackett

#  PowerShell Script To Display All SharePoint Site Collections and site Administrators In a SharePoint 2010 Farm

I would like a script that will display a list of all site collections on a Farm, and the site administrators for each site. This will help our Help Desk know who the contact people are for all sites, and will eliminate manual updates to a list/ 3/13/2012 2:58 PM | jeff critchlow

# re: PowerShell Script To Display All SharePoint Site Collection Administrators In Web Application

Jeff,

If you combine the above script with the full farm traversal pattern in the below blog post you should be able to get what you are looking for. Let me know if issues with that.

http://geekswithblogs.net/bjackett/archive/2011/09/19/powershell-script-to-traverse-all-sites-in-sharepoint-2010-or.aspx
3/13/2012 3:48 PM | Brian T. Jackett

# re: PowerShell Script To Display All SharePoint Site Collection Administrators In Web Application

This doesn't get all the subsites, you have to loop through the AllWebs to get them all:

$thesite = get-spsite "http://x.x.x.x" #thesite is an SPSite

$theWebApp = $thesite.webapplication #SPWebApplication

foreach ($site in $theWebApp.sites) #SPSite
{
foreach ($web in $site.AllWebs) #SPWeb
{
foreach ($siteAdmin in $web.SiteAdministrators) #SPWeb
{
Write-Host "$($siteAdmin.ParentWeb.Url) - $($siteAdmin.DisplayName)"
}
}
$site.Dispose()

}
$thesite.Dispose() 3/19/2013 4:09 PM | Paul

# re: PowerShell Script To Display All SharePoint Site Collection Administrators In Web Application

Paul,

Thanks for the input. The original goal of my script was only to display site collection (SPSite) administrators, not site (SPWeb) level ones. Small distinction but an important one.
3/19/2013 8:10 PM | Brian T. Jackett

# re: PowerShell Script To Display All SharePoint Site Collection Administrators In Web Application

Could you please share the script for 2007 to get the permissions for specific user in all sites collections in web app 4/23/2015 10:41 AM | Girish

Post A Comment
Title:
Name:
Email:
Comment:
Verification: