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.
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
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.