Link to home
Start Free TrialLog in
Avatar of thaapavuori
thaapavuoriFlag for Finland

asked on

While loop and powershell

I have made a loop like this

$end = Read-Host "Type"
if ($end -eq 1)
{
Funtion1
}
elseif ($end -eq 2)
{
Function2
}
else
{Write-Host "The end"}
} while ($end -eq 1)

My problem is that now this loop is working when i type number 1. But it should work with 1 and 2.  -gt is is not an option because user might type also something else than text there. Im very new with PS but this cant be very difficult.

Thanks in advance :)
Timo
Avatar of soostibi
soostibi
Flag of Hungary image

The 'do' is missing from the beginnig:

do{
$end = Read-Host "Type"
if ($end -eq 1)
{
Funtion1
}
elseif ($end -eq 2)
{
Function2
}
else
{Write-Host "The end"}
} while ($end -eq 1)
Avatar of thaapavuori

ASKER

It was my typo. There is "do" in my real script. The problem is that this loop will continue forever as it should if I type 1 but it should continue also if I type 2. Now this loop will stop after one circle if I type 2.

Thanks.

Timo
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial