Press X to exit or any other key to continue?

Grrr ... Noob question here. I want to create a block that basically does this:

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 output even if I press another key ... What am I doing wrong? Thanks!!!

+4
source share
2 answers

You should use "-eq" for comparison. A simple example:

 $a = "Powershell" IF ($a -eq "PowerShell") { "Statement is True" } ELSE { "Statement is False" } 

Here are some reads to be sure of if-then-else statements: IF_THEN_ELSE in Powershell

+7
source

Operator = intended for assignment. Use -eq to verify equality.

+2
source

All Articles