Introduction
PnP SharePoint PowerShell commands provide ways to add site collection admins to the sites. There are 2 ways,
As a Site Collection Admin adding another Site Collection Admin.
As a site collection admin, you can connect to Site Collection first and then run the command add-pnpsitecollectionadmin.
#connect to SharePoint site
Connect-PnPOnline -Url "https://contoso.sharepoint.com/sites/mytestsite" -Interactive
Add-PnPSiteCollectionAdmin -Owners "[email protected]"
#Adding multiple users by separating the user names with comma
Add-PnPSiteCollectionAdmin -Owners "[email protected]","[email protected]"
As a Site Collection Admin removing another Site Collection Admin.
#Removing Site Collection admin with specific email
Get-PnPSiteCollectionAdmin | ?{$_.Email -eq "[email protected]"}|Remove-PnPSiteCollectionAdmin
#Removing multiple site collection admins
#storing the users in array
$users = @("[email protected]","[email protected]")
foreach($user in $users)
{
Get-PnPSiteCollectionAdmin | ?{$_.Email -eq $user}|Remove-PnPSiteCollectionAdmin
}
As a SharePoint admin,
#Connect to admin portal using SharePoint or global admin creds
Connect-PnPOnline -Url https://contoso-admin.sharepoint.com -Interactive
#Adding single user as site collection admin
Set-PnPSite -Identity "https://contoso.sharepoint.com/sites/MyTestSite" -Owners "[email protected]"
#Adding multiple user as site collection admin
Set-PnPSite -Identity "https://contoso.sharepoint.com/sites/MyTestSite" -Owners "[email protected]","[email protected]"
Conclusion
Thus in this blog, we have seen how to add multiple users and remove multiple users to the SharePoint site using PnP power shell commands. I hope you find it useful.