Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with variables

Status
Not open for further replies.

fortage

MIS
Jun 15, 2000
329
0
0
US
The following Exchange 2007 cmdlet adds the $var variable literally to the -Recipient filter UserPrincipalName instead of adding "Eng Dept". I've tried it these different formats with no luck. The cmdlet requires this single quotes. How can use a variable with this cmdlet in Powershell?
'*@$vOU'
'"*@$vOU"'
"'*@$vOU'"
"*@$vOU"
''*@$vOU''
'''*@$vOU'''
\'*@$vOU\'

############
$var = "Eng Dept"
New-EmailAddressPolicy -Name "Test Name" -EnabledPrimarySMTPAddressTemplate "SMTP:%s@domain.com" -RecipientFilter {((ObjectCategory -like 'user') -and (UserPrincipalName -like '*@$var'))}
############
 
Have you tried it like this?

New-EmailAddressPolicy -Name "Test Name" -EnabledPrimarySMTPAddressTemplate "SMTP:%s@domain.com" -RecipientFilter {((ObjectCategory -like 'user') -and (UserPrincipalName -like $var))}


Light travels faster than sound. That's why some people appear bright until you hear them speak.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top