Advanced Windows PowerShell Scripting Video Training

Advanced Windows PowerShell Scripting Video Training
Advanced Windows PowerShell Scripting Video Training

Thursday, December 8, 2011

Case sensitive “Contains” operator in PowerShell

In PowerShell, we can use the –contains operator to determine if a string contains something that we care looking for.  Here is an example:

 

$collection = "One","Two","Three"
$collection -contains "One"

In this example, True would be returned. In the next example, True would also be returned.

$collection -contains "one"

The difference is the ‘O’ is lower case.  This may not serve your needs if case sensitivity is a requirement.  The below code will prove a case sensitive test.

 

$collection -ccontains "one"

 

Now the result will be False.

No comments: