I am having trouble getting a simple switch statement to work in a Powershell script I'm using. Had previously been using nested if's and wanted to clean up a bit. Code is below.
When I walk it through Powershell ISE in debug and evaluate the tests (e.g. $_ -match 'match1' ) it does evaluate to true as expected based on the value of $mystring. However, it never seems to properly execute the code associated with that value in the Switch block. I'm sure I'm missing something obvious, and appreciate any guidance. Hope my description makes sense. I'm running v5.1.
Switch ($myString)
{
($_ -match 'match1') { somecodeblock }
($_ -match 'match2') { somecodeblock }
($_ -match 'match3') { somecodeblock }
($_ -match 'match3') { somecodeblock }
($_ -match 'match4') { somecodeblock }
($_ -match 'match4') { somecodeblock }
}