2

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?

  • 1
    Is 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 – blaughw Mar 23 '15 at 22:23
  • I've tried Add first, even Add alone but the array syntax doesn't seem to work. Question updated with version info... – jcarpio Mar 23 '15 at 23:35
  • More 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. – Todd Wilcox Mar 23 '15 at 23:38
  • I 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). – peteski Oct 6 '15 at 10:03
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"}
  • Splitting the operation atomically sounds reasonable. However, just running the Add (first) I still get "All groups must have at least one owner who manages membership, message approval, and other settings for the group. Make sure you assign an owner for this group. + CategoryInfo : NotSpecified: (:) [], RecipientTaskException + FullyQualifiedErrorId : A28AC387" – jcarpio Mar 25 '15 at 21:16
  • 1
    @jcarpio interesting ... Could it be that "Gerald" cannot actually be resolved to a principal? – Mathias R. Jessen Mar 25 '15 at 21:17
  • No, I just used that as a simple example. I use get-user to capture the member. – jcarpio Mar 25 '15 at 21:41
2

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

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.