Author Posts

February 2, 2018 at 3:13 am

Sorry for this simply one, but can someone explain why when I enter any number between 1-5 the Get-Service doesn't execute.

I also tired ($sel -eq "1","2","3","4","5" )



$sel = Read-Host -Prompt "Enter number 1-5"

While ($sel -eq 1,2,3,4,5 ) {

#below doesn't happen when enter 1-5 

Get-Service t* | Where-Object {$_.Status -eq "Stopped"}


February 2, 2018 at 4:10 am

1,2,3,4,5 is an array of five items. Any single item, like 1, is not equal to an array. You may want to use the -in operator instead.

February 2, 2018 at 8:37 pm

While (1,2,3,4,5 -eq $sel) {

would actually work (I sort of learned this from the Iron Scripting). But do you want to keep repeating the body of the while loop over and over without asking for new input?