Scenario: Add a user as the manager of a distribution group without removing existing managers via Exchange PowerShell. If you were to use the Set-DistributionGroup command with the -managedby switch, it would remove the existing managers and set the managers you specified in the switch. To add the user jdoe1 as a manager and not remove the existing managers from the distribution group ‘HQ-All Employees’, run the following PowerShell commands below.
$Group = Get-DistributionGroup “HQ-All Employees”
$Managers = $Group.ManagedBy
$User = Get-User jdoe1
$Managers += $User
Set-DistributionGroup “HQ-All Employees” -Managedby $Managers -BypassSecurityGroupManagerCheck
Excel Magic: If you have an Excel sheet full of groups in Column A and wish to add jdoe1 as the manager to each of those groups, copy the Excel formula below and drag it down for the entire list of groups. The value of each cell will create the Powershell command that you will need for each group. Copy the cells (the cell values) and Paste it into Exchange PowerShell. Each command is separated by a ; so the 5 PowerShell commands needed will fit into one Excel Cell and fit on one PowerShell line for each group.
=”$Group= Get-distributiongroup “””&A2&”””; $Managers= $grp.managedby; $User=Get-User jdoe1;$Managers+=$User;Set-DistributionGroup “””&A2&””” -managedby $Managers -BypassSecurityGroupManagerCheck”