Saturday, October 23, 2021

Adding Multiple Users As Site Collection Admin

 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 ""
#Adding multiple users by separating the user names with comma
Add-PnPSiteCollectionAdmin -Owners "",""
JavaScript

As a Site Collection Admin removing another Site Collection Admin.          

#Removing Site Collection admin with specific email
Get-PnPSiteCollectionAdmin | ?{$_.Email -eq ""}|Remove-PnPSiteCollectionAdmin
#Removing multiple site collection admins
#storing the users in array
$users = @("","")
foreach($user in $users)
{
    Get-PnPSiteCollectionAdmin | ?{$_.Email -eq $user}|Remove-PnPSiteCollectionAdmin
}
JavaScript

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 ""
#Adding multiple user as site collection admin
Set-PnPSite -Identity "https://contoso.sharepoint.com/sites/MyTestSite" -Owners "",""
JavaScript

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. 

No comments:

Post a Comment

No String Argument Constructor/Factory Method to Deserialize From String Value

  In this short article, we will cover in-depth the   JsonMappingException: no String-argument constructor/factory method to deserialize fro...