Assistants with substitution

This topic contains 3 replies, has 3 voices, and was last updated by  Dave Wyatt 4 years, 8 months ago.

  • Author
  • #10417

    James Horn

    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.

  • #10418

    Dave Wyatt

    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.

  • #10419

    Richard Siddaway

    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

  • #10420

    Dave Wyatt

    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. 🙂

You must be logged in to reply to this topic.