Forum Discussion
Naligurtan
Dec 21, 2023Brass Contributor
How to add a MS365 group to many SharePoint sites as Site collection administrator
Hello All,
I have over 500 sites in Excel file/.scv.
I created a MS365 group and added several users.
Now, I want to add this MS365 group to all 500 sites as Site Collection Administrator.
I need to do it with PowerShell. I hope someone out there would be able to help asap.
Thanks
You will need to Modify this one to fit your needs such as looping through the CSV/excel but it should give you a base and understanding:
#Parameters $SiteURL = "https://contoso.sharepoint.com" $GroupOwner= "email address removed for privacy reasons" Try { #Connect to PnP Online Connect-PnPOnline -Url $SiteURL -Interactive #Get the Site $Site = Get-PnPSite -Includes GroupId #Add Group to Microsoft 365 Group connected to the site Add-PnPMicrosoft365GroupOwner -Identity $Site.GroupId -Users $GroupOwner } Catch { write-host -f Red "`tError:" $_.Exception.Message
- NaligurtanBrass ContributorThanks. The problem is I don't have much experience of PowerShell. I would appreciate if you could please write down how to pick up data from .csv file etc.
- Why not give it a try and if you get stuck i'll try to help you 🙂 This is a perfect use-case to learn!
Try to break it down to these steps:
1. Import the CSV to powershell
2. Iterate through the CSV
3. Apply the groups through each iterations