Home Computer Sharepoint Add an additional Sharepoint Admin to every Site Collection via Powershell

Add an additional Sharepoint Admin to every Site Collection via Powershell

0

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;
}

 

NO COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Exit mobile version