David Strome's Blog

A Microsofty's ramblings on Exchange Server and other stuff.

Multivalued Properties in Exchange 2010

Multivalued Properties in Exchange 2010

  • Comments 3
  • Likes

This blog article is based on a wiki page that I created for our Exchange 2010 SP2 Technology Adoption Program (TAP) private wiki site. This new syntax will make it into the Modifying Multivalued Properties topic when SP2 ships. Since the syntax also works with SP1 (the update just happens to be timed with SP2), I wanted to get this out. I hope you find it useful!


 

If you work with the Exchange Management Shell, you’re probably aware that some parameters on cmdlets can accept multiple values. These parameters are associated with “multivalued properties". If you’ve worked with multivalued properties, you’re probably also aware that it’s very easy to accidentally overwrite these properties when you attempt to add a value to them. That’s because the behavior in the shell is generally to overwrite the existing value in a property, rather than add to it. For example, assume that you have a distribution group, and you’ve configured David, Chris, and Susan to be able to manage them:

Get-DistributionGroup Sales | Format-List ManagedBy

ManagedBy : {Contoso.com/Users/david, Contoso.com/Users/susan, Contoso.com/Users/chris}

And now you want to allow a fourth user, Gary, to manage the distribution list. So you go and run the following command:

Set-DistributionGroup Sales -ManagedBy Gary

To your dismay, this is what you see when you re-run the Get-DistributionGroup cmdlet from above:

ManagedBy : {Contoso.com/Users/gary}

When you ran the Set-DistributionGroup cmdlet, the value that you specified with the ManagedBy parameter overwrote the existing value of that property. You probably didn’t want to do that. Previously there was a way to get around this by storing values in a temporary variable, adding a value to that, and then hefting all of that back to the actual property (see Modifying Multivalued Properties for all the gory details). Removing values from a multivalued property was just as cumbersome.

In Microsoft Exchange Server 2010 Service Pack 1, however, there’s a much easier way to add and remove values from a multivalued property. With this new syntax, you simply specify the syntax, along with the value or values to add or remove to or from the property, as a value on the parameter when you run the cmdlet. Here’s the new syntax:

To add a value:

@{Add="<value1>", "<value2>", "<value3>"}


To remove a value:

@{Remove="<value1>", "<value2>", "<value3>"}

The syntax is then specified as a parameter value on a cmdlet:

Set-SomeCmdlet -Parameter @{Add="<value1>", "<value2>", "<value3>"}

If we use the example with the distribution above again and want to add Gary, we would use the following command:

Set-DistributionGroup Sales -ManagedBy @{Add="Gary"}

Now when you run the following command again:

Get-DistributionGroup Sales | Format-List ManagedBy 

Here’s what you’ll see:

ManagedBy : {Contoso.com/Users/david, Contoso.com/Users/gary, Contoso.com/Users/susan, Contoso.com/Users/chris}

As you can see, Gary’s been added to the ManagedBy property and the other users remain. Now, let’s assume you want to remove David from the ManagedBy property and add Gerald at the same time. You can combine Add and Remove operations in the same command by separating the Add and Remove commands with a semi-colon. Here’s the syntax to use:

@{Add="<value1>", "<value2>"; Remove="<value1>", "<value2>"}

So to remove David and add Gerald at the same time, you’d use the following command:

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

When you run the following command:

Get-DistributionGroup Sales | Format-List ManagedBy 

You’ll see that David has been removed from the property and Gerald has been added.

Hopefully you’ll agree that this new syntax makes it much simpler to manage multi-valued properties. Of course, you can continue to replace all the values stored in a multi-valued property by assigning new values directly.

Comments
  • An example of using more than literal strings

    I thought I would be able to use something like this for removing unwanted smtp’s

    [array]$MailboxToChange = Get-Mailbox -Identity 'Username@whatever'

     $MailboxToChange | Set-Mailbox  -EmailAddresses @{ Remove="smtp:$($_.Alias)@bad.whatever"}

    But I ended up needing to use . . . . .

    Clear-Host

    [array]$MailboxToChange = Get-Mailbox -Identity 'Username@whatever'

    $MailboxToChange | ForEach-Object {

     $Badsmtp = $_.Alias

     $_ | Set-Mailbox  -EmailAddresses @{ Remove="smtp:$Badsmtp@bad.whatever"}

    } # End ForEach-Object

    I am not quite sure why the first example would not make the change that works in the second

  • This would be great if it actually worked.  Searching the net, others get the same error as I do when trying to add using the above syntax:

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

    e sure you assign an owner for this group.

       + CategoryInfo          : NotSpecified: (:) [], RecipientTaskException

       + FullyQualifiedErrorId : A14DD11B

  • I am trying to use Import-csv filename.csv | ForEach {Set-DistributionGroup "Group-Name" -AcceptMessagesOnlyFrom((Get-DistributionGroup "Group-Name").AcceptMessagesOnlyFrom + $_.Alias)} when the CSV has about 20 names. the first time I ran it, it added the last name on the list. The second time I ran it, it errored saying "username" was already added and then added the second from last name on the list. Why is it not adding the whole list?

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment