PowerShell v3 -In and–NotIn Operators

Two new operators have been added to PowerShell v3, –In and –NotIn. These are great for folks like me who are used to having this functionality in T-SQL. The syntax is very simple.

    $value = 3
    if ($value -in (1,2,3)) 
      {"The number $value was here"}

Produces:

The number 3 was here

The not in syntax is just as easy:

    $array = (3,4,5,7)
    if (6 -notin $array) 
      {"6 ain't there"}

Will yield:

6 ain't there

Very simple, but much needed additions to the PowerShell language.

Warning: This post was created using the PowerShell v3 BETA. Changes between now and the final release may affect the validity of this post.

Advertisements

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: