Back to script samples page
Assign group members to SharePoint site

By default each SharePoint site is created from a standard template (eg. STS#0) is created with three membership groups, Owners, Members, and Visitors; with Full Control, Contribute, and View-only site permissions respectively. Populate these groups using the following script.

#Assign group members to SharePoint site.

#To begin, you will need to load the SharePoint Online module to be able to run commands in PowerShell. You must also replace the url "https://contoso-admin.sharepoint.com" and use your SharePoint administrative site. 
Import-Module Microsoft.Online.Sharepoint.PowerShell 
$credential = Get-credential 
Connect-SPOService -url https://contoso-admin.sharepoint.com -Credential $credential 
 
# By default each site created from a standard template (eg. STS#0) is created with three membership groups, Owners, Members, and Visitors; with Full Control, Contribute, and View-only site permissions respectively. Populate these groups using the following script. 
# 
#  Site,Group,User 
#  https://contoso.sharepoint.com/sites/TeamSite,Contoso Team Site Members,user2@contoso.com 
#  https://contoso.sharepoint.com/sites/TeamSite,Contoso Team Site Members,user3@contoso.com 
#  https://contoso.sharepoint.com/sites/TeamSite,Contoso Team Site Visitors,user4@contoso.com 
#  https://contoso.sharepoint.com/sites/Blog,Contoso Blog Members,user5@contoso.com 
#  https://contoso.sharepoint.com/sites/Blog,Contoso Blog Visitors,user6@contoso.com 

Import-Csv .\SPOUserGroups.csv| % {Add-SPOUser -Site $_.Site -Group $_.Group -LoginName $_.User}
Downloaded 0 times
* * * * * (1)
Comments

No Comments