Advanced Windows PowerShell Scripting Video Training

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

Wednesday, February 1, 2012

Case Sensitive PowerShell–Contains Comparison Operator

In PowerShell, you can test to see if a variable or array contains a specific piece of data.  Take the following example:

$Arr1 = "PowerShell","Rocks","The","Windows","World"

If I was interested in knows if this array contained the string “rocks”, I would execute this command:

$Arr1 -contains "rocks"

The response would be True.  Notice that in the array, the data is spelled with a capitol letter.  The query used a lower case letter.  PowerShell has a case sensitive contains operator called ccontains.  When the same query is executed, but this time with ccontains, the answer returned is False.  If the query was changed to

$Arr1 -ccontains "Rocks"


Then the response would be True

No comments: