Question:
Grrr… Noob question here. I want to create a block that basically does this:
1 2 3 4 5 6 7 |
Write-Host "Press X to cancel or any other key to continue" $continue = Read-Host If ($continue = "X") {exit} else {Write-Host "Hello world"} |
Keeps exiting even if I press another key… What am I doing wrong? Thanks!!!
Answer:
You should use “-eq” for comparsion. Simple example:
1 2 3 4 5 6 7 8 9 10 |
$a = "Powershell" IF ($a -eq "PowerShell") { "Statement is True" } ELSE { "Statement is False" } |
Here is some reading to be confident with “if-then-else” statements: IF_THEN_ELSE in Powershell