?
Solved

While loop and powershell

Posted on 2011-05-03
3
Medium Priority
?
779 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:thaapavuori
3 Comments
 
LVL 13

Expert Comment

by:soostibi
ID: 35513979
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)
0
 

Author Comment

by:thaapavuori
ID: 35514012
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
0
 
LVL 71

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 35514154
Just use
    while ($end -eq 1 -or $end -eq 2)
instead.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Loops Section Overview

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question