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.
- Connect-SPOService -Url https:
- Get the Site Collection under which we will create our permission group.
- $site = Get-SPOSite https:
- Create new group as per our requirement,
- $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.
-
The above script will create new user under “Kirti Designer” group as in following figure.
Hope this blog will help you. Thank you.