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'))}
############
'*@$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'))}
############