Assistants with substitution

I have some code:
$Extension = “41042”
$ummbx = get-ummailbox -DomainController “WinAD01” -filter {(EmailAddresses -like “EUM:${Extension}”)}
Which $ummbx comes back $null
If I do:
$Extension = “41042”
$ummbx = get-ummailbox -DomainController “WinAD01” -filter {(EmailAddresses -like “EUM:41042”)}

$ummbx comes back with the information I expect. I know it has to do with EUM:${Extension} but not sure how to fix it.

Any help will be greatly appreciated.

Try it like this:

$ummbx = get-ummailbox -DomainController ‘WinAD01’ -Filter “EmailAddresses -like ‘EUM:${Extension}’”

The Filter parameter is expecting a string, not a script block. While script blocks can be implicitly casted to strings, it doesn’t always work the way you expect. The syntax I’ve suggested is what always works for me in the ActiveDirectory cmdlets; hopefully it also works in this GetUMMailbox command, though I haven’t tried it before.

The -Filter parameter may be a string but PowerShell is parsing that string as if it was a command suggesting that the problem lies more with the substitution than the format of the filter. I’ve consistently used the {property -operator value} syntax in AD & Exchange cmdlets without problem

It’s just something to try. I’ve come across a few situations where the string syntax worked, and a script block did not. I don’t know why, but I pass all my filters as double-quoted strings now, just in case.

If it helps in this case, great. If not, the problem is somewhere else. :slight_smile: