Using powershell to create new Office365 groups with specific permissions

Copper Contributor

I have a PowerShell question were my developer cannot find the answer.

We have made a script to automatically setup libraries and assign users / groups with specific permissions to these libraries.

However the libraries and permissions are created successfully but the Office 365 groups are not assigned. Office 365 users are successfully assigned including their permissions.

After investigating this issue:

We discovered only SharePoint groups can be assigned and NOT the Office 365 groups.

I do not want to assign SharePoint- or nest groups.

Currently the script (group part) looks like this.

              #Assign list permissions to the group

                if ($GroupName -ne "") {

                    #Explode Groups

                    $GroupNames = $GroupName.Split(',')

                    $GroupPermissions = $GroupPermission.Split(',')

                    $groups = $Web.SiteGroups



                    foreach ($group in $groups) {

                        if ($GroupNames.Contains($group.Title)) {                          

                            $NameIndex = $GroupNames.IndexOf($group.Title);

                            foreach ($roleDef in $roleDefs) {

                                if ($GroupPermissions[$NameIndex].Equals($roleDef.Name)) {



                                    $RoleDB = New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($Ctx)





                                    $Ctx.Load($List.RoleAssignments.Add($group, $RoleDB))



                                    Write-Host -f Green "`tAdded $GroupPermissions[$NameIndex] permission to $GroupName group in $LibraryName. "







I found something with unified groups:

# Get the membership and ownership information of an Office 365 group/all the Office 365 groups in your tenant

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session -DisableNameChecking

Get-UnifiedGroup -Identity "officekundig"

However my developer told me he cannot use this piece of code inside the script.

Please be so kind and let me know what Powershell can be used to assign Office 365 groups with a specific role to a new library.

0 Replies