Powershell – Distribution Group Owner Management Exchange PowerShell

exchangeexchange-2010powershell

In an Exchange 2010 (version 14.3 Build 123.4) environment, how do you add a new user to the "ManagedBy" attribute and remove another at the same time via PowerShell? (I'll be doing this for multiple lists using foreach)

In this TechNet blog post, http://blogs.technet.com/b/dstrome/archive/2011/05/29/multivalued-properties-in-exchange-2010.aspx the array syntax, (I've tried Add before Remove, same results):

Set-DistributionGroup Sales -ManagedBy @{Remove="David"; Add="Gerald"}

results in the message:

All groups must have at least one owner who manages membership, message approval, and other settings for the group.

What is the correct way to add and remove managers from Exchange 2010 distribution groups?

Best Answer

If the end result is to replace "David" with "Gerald" as the owner, avoid the Add/Replace syntax altogether:

Set-DistributionGroup Sales -ManagedBy "Gerald"

If you must do these two operations atomically (if you have cases where you might not want to replace existing values), split it into two distinct operations:

Set-DistributionGroup Sales -ManagedBy @{Add="Gerald"}
Set-DistributionGroup Sales -ManagedBy @{Remove="David"}