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
------------------------------------------------
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
------------------------------------------------
Thanks! It worked :)
ReplyDeleteDo you have one that works for OneDrive for Business? I think this doesn't work because I am trying a personal site.
ReplyDeleteI'm getting:
Set-PnPTenantSite : The managed path personal/user_name_contoso_co_uk is not a managed path in this tenant.