Use the –Filter, Luke


Quite often, I see questions like “Why is my Get-Recipient command so slow?”, with a syntax like:

001
002
003
$user1 = Get-Recipient -ResultSize unlimited `
|Where-Object {$_.emailaddresses -eq `
‘karlmitschke@contoso.com’}

You would think that would work lickity split, because there is only 1 result, me.

Ah, not so fast, grasshopper.  We are doing client side filtering – all recipients are returned by the Get-Recipient call, and THEN we pass those objects to the Where-Object.

On my Exchange 2007 system, this takes over a minute to return my information in $user1

So, I did some research, and read about –Filters and doing server side filtering:

http://blogs.technet.com/evand/archive/2007/02/19/filterable-properties-in-exchange-2007-rtm.aspx and http://technet.microsoft.com/en-us/library/bb738155.aspx

Modifying my script to use the –Filter produces results in less than 1 second:

001
002
$user2 = Get-Recipient -Filter `
{EmailAddresses -eq ‘karlmitschke@contoso.com’}

I suggest that you check for the –Filter parameter for any cmdlet that you use, and learn its syntax!

Advertisements
  1. Leave a comment

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: