Exchange 2007 Powershell Bulk Update of Email Address Policies

I have a csv import file which I'm trying to use to modify our 80-odd email address policies (legacy thing!)

import-csv eaps02.csv | foreach {set-EmailAddressPolicy -identity $_.name -recipientfilter {(Department -like $_.nacs) -and (RecipientType -eq  'UserMailbox') } }

The csv looks like this:-
Name,NACS,Priority,Last Modified Time,Applied,FIND
Smith Surgery (J81025),'J81025*',27,06/04/2010 12:05,FALSE,14
Jones Surgery (J81059),'J81059*',28,06/04/2010 12:05,FALSE,21

The errors are on the lines of:-
Set-EmailAddressPolicy : Cannot bind parameter 'RecipientFilter' to the target.
 Exception setting "RecipientFilter": "Unable to cast object of type 'System.Ma
nagement.Automation.PSObject' to type 'System.String'."
At line:1 char:91
+ import-csv eaps02.csv | foreach {set-EmailAddressPolicy -identity $_.name -re
cipientfilter  <<<< {(Department -eq $_.nacs) -and (RecipientType -eq  'UserMai
lbox') } }

I think the $.nacs variable is the problem and have tried various quotes & brackets in the code and the csv with no luck.
Thank you.
Dorset1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wonko_the_SaneCommented:
just a wild guess, but does $_.nacs have a working ToString() method?
Basically, does $object.nacs.ToString() return anything useful
0
Dorset1Author Commented:
I've found that Recipientfilter doesn’t accept pipeline input - doh!
However, I would appreciate an alternative way of doing this if possible.
0
Dorset1Author Commented:
That doesn't help thanks anyway

import-csv eaps02.csv | foreach {set-EmailAddressPolicy -identity $_.name -recipientfilter { (Department -like $object.nacs.ToString() -and RecipientType -eq  'UserMailbox') }}
Set-EmailAddressPolicy : Cannot bind parameter 'RecipientFilter' to the target.
 Exception setting "RecipientFilter": """ is not a valid operator. For a list of supported operators see the command help.
"(Department -like $object.nacs.ToString() -and RecipientType -eq  'UserMailbox
') " at position 26."
At line:1 char:91
+ import-csv eaps02.csv | foreach {set-EmailAddressPolicy -identity $_.name -re
cipientfilter  <<<< { (Department -like $object.nacs.ToString() -and RecipientT
ype -eq  'UserMailbox') }}

import-csv eaps02.csv | foreach {write-host $object.nacs.ToString() }
You cannot call a method on a null-valued expression.
At line:1 char:66
+ import-csv eaps02.csv | foreach {write-host $object.nacs.ToString( <<<< ) }
0
Wonko_the_SaneCommented:
yeah that was a misunderstanding...
I meant that you should store one of the objects in $object :)
in your case it would $_.nacs.ToString(), the thing I mentioned was just to test if it gives a decent output before piping it into a different command
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dorset1Author Commented:
Thanks. Adding a temporary variable ($thisnacs) seems to have resolved the issue:-
import-csv eaps02.csv | foreach {$thisnacs=$_.nacs; set-EmailAddressPolicy -identity $_.name -recipientfilter { (Department -like $thisnacs) -and (RecipientType -eq  'UserMailbox') }}
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Exchange

From novice to tech pro — start learning today.