Wednesday, December 15, 2010

Wildcard Search for Exchange Recipients PowerShell Function

I wanted to do a partial string search against names and aliases, and used the output from the Exchange Management Shell Command Log to write a PowerShell function that returned the type of broad result set I wanted, finding a match with names OR aliases.

function Get-Recip
param (
[string]$Filter=$(throw 'Partial Recipient Name or Partial Recipient Alias required')

# Wildcard search prepended and appended to filter string passed, limit result set to 1000 matches

$Filter= "*"+ $Filter + "*";

Get-Recipient -PropertySet ConsoleLargeSet -ResultSize '1000' -SortBy DisplayName `
-RecipientType 'DynamicDistributionGroup','UserMailbox','MailContact','MailUser', `
'MailUniversalDistributionGroup','MailUniversalSecurityGroup','MailNonUniversalGroup' `
-Filter {(Name -like $Filter ) -OR (Alias -like $Filter)}


No comments: