Friday, August 24, 2018

Nesting Groups in Office 365

Nesting Groups has been a bit of a pain in Office 365 for a while now but there's apparently a few answers (and some updates on the way).  

Here's a PowerShell method. 

The Setup

To start with, we're going to create a group in Office365 Admin. It should be a mail enabled security group.

In our example the group will be called;

GRP MotherGroup
and it will have an email address of
(obviously the domain will be different at your location).

For the purposes of this exercise, you'll also want to create several groups to be nested.
These are distribution groups and their names and emails for the purposes of our demonstration will be;
GRP BabyGroup1
GRP BabyGroup2
GRP BabyGroup3
GRP BabyGroup4

The PowerShell Commands

As usual, you'll want to run PowerShell in Administrator Mode.

Set-ExecutionPolicy RemoteSigned
Press Y and Enter.

$UserCredential = Get-Credential
You'll be prompted to logon with your user name and password.  If you have multi-factor authentication enabled, you'll probably have a few extra hoops to jump through here.

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

This creates the session

Import-PSSession $Session

This activates the session.

The next command is specific to your group. It looks like this (boldfaced parts will be replaced).

Add-DistributionGroupMember -Identity -Member

If you're following our example, the commands would be as follows;
Add-DistributionGroupMember -Identity -Member
Add-DistributionGroupMember -Identity -Member
Add-DistributionGroupMember -Identity -Member
Add-DistributionGroupMember -Identity -Member

As usual, because we're neat people, we remove our session before exiting...
Remove-PSSession $Session

If you go into the Office 365 Admin console, you should be able to find your group, now with the nested subgroups below it. It's a painful process but it works.

No comments: