The problem is that the loop is working the first time but it stops after and I want it to continue like this until the input is different than 1 to 9.
do
{
Show-Menu
$selection = Read-Host "Please choose an option"
switch ($selection)
{
'1' {
Get-ChildItem
} '2' {
get-host|Select-Object
} '3' {
Get-NetIPConfiguration -Detailed
} '4' {
Get-NetRoute
} '5' {
Get-DnsClientCache
} '6' {
Get-Date -UFormat "%A %B/%d/%Y %T %Z"
} '7' {
Get-ItemProperty -Path HKLM:\
} '8' {
Stop-Service -Name Spooler -Force
Restart-Service -Name Spooler -Force
} '9' {
Get-Service | Where-Object {$_.Status -eq "Running"}
}
}
pause
}
until ($selection -ne 1..9)
I tried a while loop but it did an infinite loop...
CodePudding user response:
The only issue with your code is the use of -ne
:
until ($selection -ne 1..9)
Instead of -notin
:
until ($selection -notin 1..9)