Give Access to Site Collection in SharePoint Online / Office 365

Requirement

In my training after creating my site collection in SharePoint Online, I want to grant user’s access to the Site Collection. First I want to create a new SharePoint group for my personal use and then want to add users to my group. To fulfil my requirement I need to use the New-SPOSiteGroup cmdlet and the Add-SPOUser cmdlet, respectively.

New-SPOSiteGroup cmdlet requires only three parameters, the name of the group to create, the permissions to add to the group, and the Site Collection within which to create the group. Once my group is created I can then use the Add-SPOUser cmdlet to add a user to the group.

In the following example I’m creating a new group named “Kirti Designers” and giving it the “Design” permission and then add a user to the group. We need site collection administrator rights to perform this task.

Script 
  • Connect to SharePoint Online by using the following PowerShell command. It takes the URL of our tenant admin and a username. Then it will ask for password.
    1. Connect-SPOService -Url https://moharanakirti-admin.sharepoint.com -Credential [email protected]  
  • Get the Site Collection under which we will create our permission group.
    1. $site = Get-SPOSite https://moharanakirti.sharepoint.com/portals/community -Detailed  
  • Create new group as per our requirement,
    1. $group = New-SPOSiteGroup -Site $site -Group "Kirti Designers" -PermissionLevels "Design“   

(We could just as easily provide the string URL directly as site parameter).

The above script will create a new group under provided site collection as in following figure.
 

 

  • Now I am adding a new user to newly created group.
    1. Add-SPOUser -Site $site -Group $group.LoginName -LoginName "[email protected]"   

The above script will create new user under “Kirti Designer” group as in following figure.
 

 Hope this blog will help you. Thank you.