How do you Compare?

Most people throw things at a problem and see what sticks.

Is this a true “solution” or a makeshift glue that can come unraveled at any given moment.

apples to oranges

I think that when we compare we should understand what is needed and not needed, and really understand our options.

Understand the basics

This is an example of a variable with text defined. we want to look for the word Fruit.

PS C:\> $Apple = "Red Fruit, Green Fruit, Yellow Fruit"

PS C:\> $Apple -match 'Fruit'

PS C:\> $Apple | where {$_ -match 'Fruit'}
Red Fruit, Green Fruit, Yellow Fruit

PS C:\> $Apple -like 'Fruit'

PS C:\> $Apple | where {$_ -like 'Fruit'}


So it looks like “Like” doesn’t like to be used in the way you cognitively expect.

PS C:\> $apple -like '*Fruit*'

PS C:\> $apple | where {$_ -like '*Fruit*'}
Red Fruit, Green Fruit, Yellow Fruit

Well there is a trick to it. The trick is it has rules that govern how it looks at the compared objects and if it care about what comes before or after the string you are looking for.

I like to use match. some instances like the Active Directory module that comes with RSAT doesn’t allow it with the -filter parameter. you can pipe and filter instead.

Take a look below:

PS C:\> get-aduser -filter {givenname -like *Xajuan*}

VS the pipeline equivalent below:

PS C:\> get-aduser -filter * | where {$_.givenname -match

Either way stay true to your comfort zone and be sure to explore outside it, because at the end of the day, you got to get the job done, and nothing compares like that is complete.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.