• 1. London, UK
  • 2. Sydney, Australia
  • 3. New York, NY
  • 4. Melbourne, Australia
  • 5. Paris, France
  • 6. San Francisco, CA
  • 7. Chicago, IL
  • 8. Moscow, Russia
  • 9. Amsterdam, The Netherlands
  • 10. Toronto, Canada

Monday, February 19, 2007

 

HOW TO Update multi-valued attributes in PowerShell

Posted by Bharat Suneja at 9:13 AM
Multivalued attributes are simply attributes that can have more than one value. Examples include members attribute of groups, or proxyAddresses attribute of recipients.

In GUI interfaces, it is simple to add/modify multivalued attributes. VBScript has control codes that allow you to control the interaction with multi-valued attributes - 1 = clear all entries, 2 = update all entries, 3 = append, and 4 = delete.

Exchange shell uses Add commands to add new entries to some multivalued attributes - e.g. Add-IPBlockListEntry to add another IP address or range to the IP Block List.

However, if you want to add more values to stuff like BypassedSenderDomains in ContentFilterConfig, there's no equivalent of an Add command. If you try to add a value to the attribute using the following syntax, the existing values will be replaced by the newer ones:

Set-ContentFilterConfig -BypassedSenderDomains "somedomain.com"

You could copy the existing values (e.g. microsoft.com,zenprise.com), and paste these along with the new value:

Set-ContentFilterConfig -BypassedSenderDomains "microsoft.com","zenprise.com","somedomain.com"

However, this copying and pasting can be tricky for attributes that have a lot of values. Another alternative (..thanks to Vivek for the suggestion):

$foo=Get-ContentFilterConfig
$foo.BypassedSenderDomains +="somedomain.com"
$foo | Set-ContentFilterConfig

This is a great workaround... and it works!

However, it'd be much easier to have a switch that lets you append to such multi-valued attributes, in keeping with the shell's promise of allowing most operations using one-liners.. something like Set-ContentFilterConfig -BypassedSenderDomains +domainthree.com,domainfour.com to add values to the attribute, and some other combination to remove a particular value.

Update:
To remove a value from a multivalued attribute, for example from the BypassedSenderDomains property of the ContentFilterConfig used in the preceding example:

$foo=Get-ContentFilterConfig
$foo.BypassedSenderDomains -="somedomain.com"
$foo | Set-ContentFilterConfig

Labels: , , ,

5 Comments:

January 14, 2008 7:13 AM
Anonymous Anonymous said...

The correct syntax for adding multiple values is

Set-ContentFilterConfig -BypassedSenderDomains "microsoft.com","zenprise.com","somedomain.com"

 
April 4, 2008 7:08 AM
Anonymous Anonymous said...

The problem I have been having with powershell and anti-spam is this....

say I did this command...

Set-ContentFilterConfig -BypassedSenderDomains "microsoft.com","zenprise.com","somedomain.com"

Ok now tommorrow I run that SAME command with different domains. It is going to wipe out everything that I put in there in the first place.

Correct me If I am wrong, but basically, you have to keep a txt file with every domain, and each time you run this command, you must include all domains. It seems to me the powershell only remembers the command 1 time, and wipes out whatever domains you had in there the last time.

This is a huge problem, because it also happens when I try to add emails to the whitelist. if you add 5 users, then 5 later, you still only have the last 5 when you output to the clipboard.

 
May 22, 2008 11:45 AM
Anonymous Onedin said...

Very useful post, thanx!

 
July 24, 2008 2:11 AM
Anonymous Anonymous said...

I tried this on the

set-attachmentfilterlistconfig

command with "ExceptionConnectors" multivalued argument

but I have the following error:

[PS] C:\Documents and Settings\Administrator>$foo.ExceptionConnectors -="f0484a1
9-771c-46a0-adb9-c5f3a92cd160"
Exception calling "op_Subtraction" with "2" argument(s): "Failed to convert f04
84a19-771c-46a0-adb9-c5f3a92cd160 from System.String to Microsoft.Exchange.Data
.Directory.ADObjectId."
At line:1 char:28
+ $foo.ExceptionConnectors -=" <<<< f0484a19-771c-46a0-adb9-c5f3a92cd160"

basically i just want to remove my connector from this Exclusion list, but i cannot find out how to do it.

 
August 12, 2008 4:03 PM
Anonymous hhc said...

This Post is Greattttttt!!!, i have been looking for something like this, i used with receive connectors to set the remoteiprange. thank you very much

 

Post a Comment

Links to this post:

Create a Link

<< Home