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/0 4/2010 12:05,FALSE,14
Jones Surgery (J81059),'J81059*',28,06/0 4/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.PSObje ct' 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.
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/0
Jones Surgery (J81059),'J81059*',28,06/0
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.PSObje
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.
ASKER
I've found that Recipientfilter doesn’t accept pipeline input - doh!
However, I would appreciate an alternative way of doing this if possible.
However, I would appreciate an alternative way of doing this if possible.
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( <<<< ) }
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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') }}
import-csv eaps02.csv | foreach {$thisnacs=$_.nacs; set-EmailAddressPolicy -identity $_.name -recipientfilter { (Department -like $thisnacs) -and (RecipientType -eq 'UserMailbox') }}
Basically, does $object.nacs.ToString() return anything useful