So let’s say you have an environment with a bajillion Site Collections and some new hire comes along and wants to be a Site Collection Administrator to every Site Collection in your farm. And because your boss said so. What would you do?
A. Tell him no way jose!
B. Add him to each Site Collection as a Site Collection Administrator manually a bajillion times. And then file for worker’s comp.
C. Tell him to manually request access to each SharePoint site as he goes along.
D. It’s PowerShell time!
If you picked D, I applaud you. Now here’s a PowerShell script that’ll carry this out for you:
# This script will add or remove a named Site Collection Administrator # to all Site Collections within a Web Application. # # Author: Henry Ong ######################## Start Variables ######################## $newSiteCollectionAdminLoginName = "domain\login" $newSiteCollectionAdminEmail = "your.email@address.com" $newSiteCollectionAdminName = "Your Display Name" $newSiteCollectionAdminNotes = "" $siteURL = "http://SharePointSiteURL" #URL to any site in the web application. $add = 1 # 1 for adding this user, 0 to remove this user ######################## End Variables ######################## Clear-Host $siteCount = 0 [system.reflection.assembly]::loadwithpartialname("Microsoft.SharePoint") $site = new-object microsoft.sharepoint.spsite($siteURL) $webApp = $site.webapplication $allSites = $webApp.sites foreach ($site in $allSites) { $web = $site.openweb() $web.allusers.add($newSiteCollectionAdminLoginName, $newSiteCollectionAdminEmail, $newSiteCollectionAdminName, $newSiteCollectionAdminNotes) $user = $web.allUsers[$newSiteCollectionAdminLoginName] $user.IsSiteAdmin = $add $user.Update() $web.Dispose() $siteCount++ } $site.dispose() write-host "Updated" $siteCount "Site Collections."
Notes: Thanks to Google and Keith Richie for the assist.
Thanks for a cool post and do you mind if I borrow the term “bajillion”?
Haha. Fo shizzles Zlatan 🙂
A better way for our needs has been to:
1) Create a AD group like domain\SharePointSiteAdmins,
2) Grant this group Full Control to the entire web application through Central Admin -> Manage web applications -> User Policy.
Thanks for the tip Steve! I like it!
Thanks for the post, saved my day 🙂
Thanks ! Simple and to the point.
Would it be complicated to modify the script so it goes through all webapp automatically
Thanks !!! Exactlu what i was looking for i have about 2000 SC and i have to remove one user from SC admin
Thanks for this Henry! It worked like a charm. I added a write progress counter to the end of your code to track the status of the script and posted to my blog with reference to yours.