Exchange: Filter Distribution Groups by Alias with a Variable


If you ever search a mailbox or distribution group in Exchange using this command:

 

    $vAlias = “Sales”

    Get-DistributionGroup -Filter { Alias -eq $vAlias }

Aaaannnddd, It doesn’t work. But This works:

 

    Get-DistributionGroup -Filter { Alias -eq “Sales” }

 

Man, that’s frustrating. But there is a solution. Set the filter query like this:

    $vAlias = “Sales”

    Get-DistributionGroup -Filter “Alias -eq ‘$vAlias'”

Tadaaaa! It is freaking works now.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s