• 1. London, UK
  • 2. New York, NY
  • 3. Sydney, Australia
  • 4. Melbourne, Australia
  • 5. Paris, France
  • 6. Bangalore, India
  • 7. Amsterdam, Netherlands
  • 8. San Francisco, CA
  • 9. Hong Kong
  • 10. Houston, TX

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: , , ,

10 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

 
January 26, 2009 11:37 AM
Blogger Gus Gallows said...

I had a similar issue with the AcceptMessagesOnlyFrom attribute of the Set-DistributionGroup. Found the following to work very well:

Set-DistributionGroup -id ‘Test Dist Group’-AcceptMessagesOnlyFrom
((Get-DistributionGroup ‘Test Dist Group’).AcceptMessagesOnlyFrom + ‘Chris Allen’)

Put all that on one line and it should work for you. I tested it and it works great.

 
April 23, 2009 2:01 PM
OpenID scoobdog50 said...

wow thanks guys this work for me .......... i was working on this all day....
you guys help big

 
August 28, 2009 3:02 AM
Anonymous Anonymous said...

Somewhere , someone forgot that the purpose of Powershells was to make things EASIER? A little box > add domain > show a list ? Easy. Faffing around with all these little scripts a huge waste of time.

 
August 28, 2009 9:40 AM
Anonymous Anonymous said...

the below commands were very helpful.....
$foo=Get-ContentFilterConfig
$foo.BypassedSenderDomains +="somedomain.com"
$foo | Set-ContentFilterConfig
AWESOME!!!!!!!!

 
February 26, 2010 7:54 AM
Anonymous Anonymous said...

What do you mean AWESOME? IT SUCKS. I've wasted all of this time looking for ways to "fix" what could have been an easy gui tab called "Whitelist domains" that would have all of my entries listed on one page with a simple "add","delete" button at the bottom. How novel; Soooo easy; User friendly even. But No - MS gives us this horrible backwards DOS prompt crap. Now I've got to create my own cheat sheet .txt file to keep track of the stupid dos commands. plus keep an additional .txt file of all of my whitelisted domains because EXCH-07 only remembers the last thing added. You ended your post with "AWESOME!!!!!!!" I'm ending mine with IGNORANT!!!!! (but I'm referring to MS, not you.)

 

Post a Comment

Links to this post:

Create a Link

<< Home