Powershell Array Comparison

I am updating my Get-ExchangeServerPlus.ps1 and I wanted to check for a hotfix in the registry.  But I wanted the ability to add more checks by adding a value to an array.

So my code is enumerating the registry using WMI and I wanted to check a registry key against my array.  I was thinking about for loops and then found this .. damm cool!

http://www.microsoft.com/technet/scriptcenter/resources/pstips/aug07/pstip0810.mspx

$arrColors = "blue", "red", "green", "yellow", "white", "pink", "orange", "turquoise"
$arrColors –contains "black"

Believe it or not, that’s all there is to it: all we have to do is use the –contains operator, followed by the value we’re searching for. As you might have guessed, the –contains operator tells us whether or not an item can be found in a group. Because the color black does not appear in our array, PowerShell is going to respond by telling us this

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: