Add multiple secondary site collection admins

I needed a way to add multiple secondary site collection admins to a single SharePoint site with the use of PowerShell. The script below helps me with this. There are multiple ways of doing this however I found that using the PnP version enables to set the Secondary owner and not the default.

You can use Set-SPOSite if you want to set the default site collection admin.

----------------------------------------------

#Admin Variables
$Adminurl = "SharePoint admin URL"
$adminAccounts = "Admin 1 comes here","Admin 2 comes here"
#$cred = Get-Credential

#Sitecollection
$SiteCollection = read-host "Put your sitecollection URL here"

#Connect to SPO
$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $SecurePWD
Connect-PnPOnline -url $Adminurl -credential $cred
write-host "Connected" -foregroundcolor green

#Set secondary siteCollection Administrators of site collection
Set-PnPTenantSite -URL $SiteCollection -Owners $adminaccounts
write-host "Added $adminaccounts as a secondary sitecollection admin" -foregroundcolor green

------------------------------------------------

Comments

  1. Do you have one that works for OneDrive for Business? I think this doesn't work because I am trying a personal site.

    I'm getting:
    Set-PnPTenantSite : The managed path personal/user_name_contoso_co_uk is not a managed path in this tenant.

    ReplyDelete

Post a Comment

Popular posts from this blog

Azure Information Protection (AIP)

Tiles modern UI

Azure Active Directory (AAD)