PowerShell mailbox filtering bug?

Asked by At

Checking if a certain address is already in use by any mailbox as SMTP or SIP address.

The below command doesn't automatically search for SIP addresses without adding the prefix so:

The above works, the below doesn't:

   Get-Mailbox -Filter 'emailaddresses -eq $SMTP -or emailaddresses -eq $SIP'

Tried ToString() and a bunch of other things but I can't get it to work with the variable, not sure what the problem is here... both variables are strings.

1 Answers

Moerwald On Best Solutions


When you enclose a string in single-quotation marks (a single-quoted string), the string is passed to the command exactly as you type it. No substitution is performed.

So the filter:

Get-Mailbox -Filter 'emailaddresses -eq $SMTP -or emailaddresses -eq $SIP'

will be used as it is ('emailaddresses -eq $SMTP -or emailaddresses -eq $SIP') no variable substitution will be done.

Change it to:

 Get-Mailbox -Filter "emailaddresses -eq $SMTP -or emailaddresses -eq $SIP"


 Get-Mailbox -Filter "emailaddresses -eq $SMTP -or emailaddresses -eq `"sip:[email protected]###.com`""

Hope that helps