Monday, June 30, 2014

Managing Distribution Group Administrators by using PowerShell

Hi Folks,

Here I would love share some simple code to tweak distribution groups administrators by using Exchange management shell.

Of course it is easier to do  by using Exchange Management Console or Exchange Admin Center (if you are using Exchange 2013), however sometimes you may need to automate this task or modify admins for more than one distribution list.

Distribution list administrators are controlled by ManagedBy property which in turn corresponds ManagedBy attribute (which can also be accessed and modified by using ADUC and have only 1 value) and to msExchCoManagedByLink (which is accessed via ADSIEDIT or Attributes editor tab of ADUC in advanced view) and can have multiple attributes.




If we modify ManagedBy propery by simply using Set-DistributionGroup with ManagedBy parameter specified, we will simply overwrite current value of this attribute which is not always what we want to achieve, in particular if we want to add more than one group admin to those currently configured.

This requires some PowerShell magic:

First we create a variable which contains the current value of the ManagedBy attribute (let's call it $Mng):

$Mng=(Get-DistributionGroup "My Dist Group").ManagedBy

Secondly we add name of our new admin to this variable:

$mng+="John Smith"


And finally, we use modified $Mng variable in configuring ManagedBy property of the distribution group:

Set-DistributionGroup "My Dist Group" -ManagedBy $Mng

I hope it will be useful to you!