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 exiting even if I press another key... What am I doing wrong? Thanks!!!
You should use "-eq" for comparsion. Simple example:
$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
The =
operator is for assignment. Use -eq
to test for equality.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With