Distribution Group Owner Management Exchange PowerShell
Solution 1
ManagedBy is a MultiValuedProperty parameter.
To add, use the plus (+) operation, see example below. To subtract, use the subtract equals (-=) operation, see second example below.
Example of adding a user:
$mgr = get-user gerald
foreach ($thing in $things) {
$group = Get-DistributionGroup $thing
$managers = $group.ManagedBy
$newmanagers = $managers+$mgr
Set-DistributionGroup -BypassSecurityGroupManagerCheck -ManagedBy $newmanagers -Identity $thing
}
And, to remove a user (using DistinguishedName):
$removethis = "CN=David,OU=Houston,DC=company,DC=com"
while iterating through the list of $managers (see above):
foreach ($manager in $managers) {
$dn = $manager.DistinguishedName
if ($dn -eq $removethis) {
$modifiedmanagers = ($managers -= $removethis)
}
}
then use that in the cmdlet:
Set-DistributionGroup -BypassSecurityGroupManagerCheck -ManagedBy $modifiedmanagers -Identity $thing
Solution 2
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"}
Related videos on Youtube
jcarpio
Updated on September 18, 2022Comments
-
jcarpio over 1 year
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?
-
blaughw about 9 yearsIs it possible the Remove action is occurring first, and therefore throwing this error before the new value is applied? Have you tried listing the Add action first in the list? Also, what version of Exchange are you running (SP and CU, as well), as it would appear that is an important consid
-
jcarpio about 9 yearsI've tried Add first, even Add alone but the array syntax doesn't seem to work. Question updated with version info...
-
Todd Wilcox about 9 yearsMore likely you'll need two separate commands. First run the add command and then the remove command. That way the timing can't be messed up.
-
peteski over 8 yearsI think the blog article isn't accurate anymore as the MSDN documentation says the Exchange 2010 version of the cmdlet doesn't have that capability (it is available in Exchange Online).
-
-
Mathias R. Jessen about 9 years@jcarpio interesting ... Could it be that "Gerald" cannot actually be resolved to a principal?
-
jcarpio about 9 yearsNo, I just used that as a simple example. I use get-user to capture the member.