Link to home
Start Free TrialLog in
Avatar of Dorset1
Dorset1

asked on

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.
Avatar of Wonko_the_Sane
Wonko_the_Sane
Flag of United States of America image

just a wild guess, but does $_.nacs have a working ToString() method?
Basically, does $object.nacs.ToString() return anything useful
Avatar of Dorset1
Dorset1

ASKER

I've found that Recipientfilter doesn’t accept pipeline input - doh!
However, I would appreciate an alternative way of doing this if possible.
Avatar of Dorset1

ASKER

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( <<<< ) }
ASKER CERTIFIED SOLUTION
Avatar of Wonko_the_Sane
Wonko_the_Sane
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Dorset1

ASKER

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') }}