Created
January 15, 2018 10:23
-
-
Save fabianneve/bc8f8faa69feb2a87f7ef9ebceddbad3 to your computer and use it in GitHub Desktop.
This script adds a user or group to the Site Collection Administrators Group of every Site Collection Farm-wide. Define your User or Group in line 2.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#example: $AccountList = @("DOMAIN\User" , "DOMAIN\Group") | |
$AccountList = @("DOMAIN\User") | |
$wapps = Get-SPWebApplication | |
Foreach($webapp in $wapps) | |
{ | |
foreach ($SiteCollection in $webapp.Sites) | |
{ | |
write-host $SiteCollection.url | |
$spweb = Get-SPWeb $SiteCollection.url | |
foreach ($Account in $AccountList) | |
{ | |
$user = Get-SPUSER -identity $Account -web $SiteCollection.url -ErrorAction SilentlyContinue | |
if ($user -eq $null) | |
{ | |
$SPWeb.ALLUsers.ADD($Account, "", "", "Added by SiteCollectionAdminScript") | |
$user = Get-SPUSER -identity $Account -web $SiteCollection.url | |
Write-host "Added user $Account to URL $SPWeb.URL" -Foregroundcolor green | |
} | |
else | |
{ | |
Write-host "user $Account was already in URL " $SPWeb.URL -Foregroundcolor red | |
} | |
if ($user.IsSiteAdmin -ne $true) | |
{ | |
$user.IsSiteAdmin = $true | |
$user.Update() | |
Write-host "$account has been made an admin on $SPWeb.URL" -Foregroundcolor green | |
} | |
else | |
{ | |
Write-host "$account was already an admin on $SPWeb.URL" -Foregroundcolor red | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment