Wednesday, April 6, 2011

Powershell multi-value attributes

Now and then you encounter that you must handle multivalued properties in Exchange Management Shell (EMS). This can be a little tricky of you don’t know how to do this.

I will give some examples to highlight different syntaxes you can use. I will use the attribute RemoteIPRanges on ReceiveConnector but examples can be used on any multi-value attribute.

Adding some IP ranges. This will overwrite every IP range already present.
Set-ReceiveConnector <Connector name> -RemoteIPRanges "192.168.10.10", "192.168.10.11"

List multivalued properties.
Get-ReceiveConnector <Connector name>).RemoteIPRanges



Adding additional IP. This is completed by first save the range array into $range variable. Adding values to the $range variable and then write the info in $range variable to the receiveconnector.

$range = (Get-ReceiveConnector <Connector name>).RemoteIPRanges

$range += "192.168.10.12"


Set-ReceiveConnector <Connector name> -RemoteIPRanges $range



You can also remove entries from the array with the same method as adding.

$range -= "192.168.10.12"



Because you have all entries in the $range variable you can do things like copy ranges from one connector to another one.

$range = (Get-ReceiveConnector <Connector name>).RemoteIPRanges

Set-ReceiveConnector <another Connector name> -RemoteIPRanges $range