PowerShell – Add or remove a site collection administrator from all sites

This is an issue I recently faced.  I needed to add myself as a site collection administrator to 100+ site collections.  I did not want to do this manually because it would have taken too much time.  So what did I do, I put it off until I got fed up with having to add myself manually each time I needed access.  I started searching for posts and found and excellent article on how to achieve this via PowerShell.

Here is the link to the original post: http://blog.henryong.com/2011/04/08/adding-or-removing-a-site-collection-administrator-from-all-site-collections/
This worked perfectly except for one minor detail….no progress indicator.  This is usually not that big of a deal since PowerShell takes care of business so quickly, but this time, I wanted to know where I was during each step of the process.  To do this, I added a loop counter to display the current percentage of operation.  Once the script has run, it will write back to your screen the exact number of site collections modified.

Thanks to Henry Ong over at The SharePoint Swiss Army Knife for the main script.

To remove someone from the site collection admins, simply change the variable $add = 1 to $add = 0.  What I did was create a separate script for removing and updated the verbage in the write progress to indicate that I was removing a user.

Stay Salty!

Leave a Reply