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 MotherGroup@mydomain.com
(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  babygroup1@mydomain.com
GRP BabyGroup2  babygroup2@mydomain.com
GRP BabyGroup3  babygroup3@mydomain.com
GRP BabyGroup4  babygroup4@mydomain.com


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 https://outlook.office365.com/powershell-liveid/ -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 MotherGroup@mydomain.com -Member babygroup1@mydomain.com
Add-DistributionGroupMember -Identity MotherGroup@mydomain.com -Member babygroup2@mydomain.com
Add-DistributionGroupMember -Identity MotherGroup@mydomain.com -Member babygroup3@mydomain.com
Add-DistributionGroupMember -Identity MotherGroup@mydomain.com -Member babygroup4@mydomain.com


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

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: