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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Wonko_the_SaneConnect With a Mentor Commented:
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
 
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
 
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
All Courses

From novice to tech pro — start learning today.