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.

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