Assistants with substitution

Welcome Forums General PowerShell Q&A Assistants with substitution

This topic contains 3 replies, has 3 voices, and was last updated by

 
Member
5 years, 3 months ago.

  • Author
    Posts
  • #10417

    Participant
    Points: 0
    Rank: Member

    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

    Member
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

    Member
    Points: 0
    Rank: Member

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

The topic ‘Assistants with substitution’ is closed to new replies.