Friday, April 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

#Runme via ".\AddAdditionalSiteCollectionAdministrator_v1.ps1 contoso\SharepintAdmin2"

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

# Buildinfos:

    [Parameter(Mandatory=$true, HelpMessage='username in format DOMAIN\username')]
    [string]$Username = "",
    [Parameter(Mandatory=$true, HelpMessage='url for web application e.g.')]
    [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
        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 "----------------------------------------------------------------------------"
    Write-Host "Could not find Web Application $WebApplicationUrl" -ForegroundColor Red;


Related Articles


Please enter your comment!
Please enter your name here

Stay Connected

- Advertisement -

Latest Articles