Thursday, December 12, 2024

Add an additional Sharepoint Admin to every Site Collection via Powershell

If a new SharePoint Administrator joined, you normally grant him SharePoint Administrator access. However that didnĀ“t mean he is able to open every website collection. To fix that issue you can use the script below.

The script will add the new SharePoint Administrator as an additional site collection administrator to every website collection. Simply run the script inside a SharePoint PowerShell via: .\AddAdditionalSiteCollectionAdministrator_v1.ps1 contoso\SharepintAdmin2 http://sharepoint.int.contoso.com


#Runme via ".\AddAdditionalSiteCollectionAdministrator_v1.ps1 contoso\SharepintAdmin2 http://sharepoint.int.contoso.com"

# =========================================================================================================================
#
# ------------- Do not change anything behind that line ! ----------------------------
#

# Buildinfos:
# https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsite_properties.aspx

param
(
Ā Ā Ā  [Parameter(Mandatory=$true, HelpMessage='username in format DOMAIN\username')]
Ā Ā Ā  [string]$Username = "",
Ā Ā Ā  [Parameter(Mandatory=$true, HelpMessage='url for web application e.g. http://sharepoint.int.contoso.com')]
Ā Ā Ā  [string]$WebApplicationUrl = ""
Ā 
)
Ā 
Write-Host "Adding user $Username as additional site collection admin on all sitecollections in Web Application $WebApplicationUrl" -ForegroundColor White;

if($webApplication -ne $null)
{
Ā 
Ā Ā  Ā foreach($siteCollection in $webApplication.Sites)
Ā Ā  Ā {
Ā Ā  Ā Ā Ā  Ā Write-Host "----------------------------------------------------------------------------"
Ā Ā  Ā Ā Ā  Ā 
Ā Ā  Ā Ā Ā  Ā $siteCollectionURL = $siteCollection.Url
Ā Ā  Ā Ā Ā  Ā Ā Ā  Ā Ā Ā  Ā 
Ā Ā  Ā Ā Ā  Ā #$siteCollection.GetType().Name
Ā Ā  Ā Ā Ā  Ā 
Ā Ā  Ā Ā Ā  Ā Write-Host "Working on $siteCollectionURL" -ForegroundColor Green

Ā Ā  Ā Ā Ā  Ā Write-Host "Adding user $Username as site collection admin" -ForegroundColor White;
Ā Ā  Ā Ā Ā  Ā New-SPUser -UserAlias $Username -Web $siteCollectionURL -SiteCOllectionAdmin
Ā Ā  Ā 
Ā Ā  Ā Ā Ā  Ā Write-Host "Current Site Collection Admins are: " $siteCollection.RootWeb.SiteAdministrators;
Ā Ā  Ā Ā Ā  Ā Write-Host "----------------------------------------------------------------------------"
Ā Ā  Ā }
}
else
{
Ā Ā Ā  Write-Host "Could not find Web Application $WebApplicationUrl" -ForegroundColor Red;
}

Ā 

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Stay Connected

35FollowersFollow
- Advertisement -

Latest Articles