![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | $Variable Is In {1,2,3,4} I'd like to read from the command line some user input, and then qualify that they entered a valid response (e.g. "A", "B", or "1"). Is there a conditional expression that can do this? Also, I've been searching through Google and MS for about 30 min now looking for, on the Microsoft site preferably, a comprehensive powershell reference (where I would have liked to have been able to find the answer to the above question). I found blogs, script examples, books.... but not just a simple repository that was comprehensive. Does one exist and can someone give me a link? Thank you |
My System Specs![]() |
| | #2 (permalink) |
| | RE: $Variable Is In {1,2,3,4} $userinput = write-host "Enter something" if ($userinput -eq "a") { "Valid" } else {"invalid" } if you want to match more complex strings you can use -match and a regex. Match a, b or 1 case insensitive: if ($userinput -match "[a,b,1]") "C S S" wrote: Quote: > I'd like to read from the command line some user input, and then qualify that > they entered a valid response (e.g. "A", "B", or "1"). Is there a > conditional expression that can do this? > > Also, I've been searching through Google and MS for about 30 min now looking > for, on the Microsoft site preferably, a comprehensive powershell reference > (where I would have liked to have been able to find the answer to the above > question). I found blogs, script examples, books.... but not just a simple > repository that was comprehensive. Does one exist and can someone give me a > link? > > Thank you |
My System Specs![]() |
| | #3 (permalink) |
| | Re: $Variable Is In {1,2,3,4} On Oct 23, 11:09*am, C S S <C...@xxxxxx> wrote: Quote: > I'd like to read from the command line some user input, and then qualify that > they entered a valid response (e.g. "A", "B", or "1"). *Is there a > conditional expression that can do this? > > Also, I've been searching through Google and MS for about 30 min now looking > for, on the Microsoft site preferably, a comprehensive powershell reference > (where I would have liked to have been able to find the answer to the above > question). * I found blogs, script examples, books.... but not just a simple > repository that was comprehensive. *Does one exist and can someone giveme a > link? > > Thank you The -contains operator might work backward from the way you usually check input but it is definitely the way to go in cases like this. You can add ,'','exit' for example and now an empty string or the word exit are allowed very simply. |
My System Specs![]() |
| | #4 (permalink) |
| | Re: $Variable Is In {1,2,3,4} On Oct 23, 12:26*pm, RickB <rbiel...@xxxxxx> wrote: Quote: > On Oct 23, 11:09*am, C S S <C...@xxxxxx> wrote: > Quote: > > I'd like to read from the command line some user input, and then qualify that > > they entered a valid response (e.g. "A", "B", or "1"). *Is there a > > conditional expression that can do this? Quote: > > Also, I've been searching through Google and MS for about 30 min now looking > > for, on the Microsoft site preferably, a comprehensive powershell reference > > (where I would have liked to have been able to find the answer to the above > > question). * I found blogs, script examples, books.... but not just asimple > > repository that was comprehensive. *Does one exist and can someone give me a > > link? Quote: > > Thank you > if ("A", "B","1" -contains $UserInput) > > The -contains operator might work backward from the way you usually > check input but it is definitely the way to go in cases like this. > You can add ,'','exit' for example and now an empty string or the word > exit are allowed very simply. 1..15,'exit' -contains $input Here any number from 1 thru 15 or 'exit' is allowed. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Ren file with variable | PowerShell | |||
| Import-CSV from Web/Variable | PowerShell | |||
| Set-Variable | PowerShell | |||
| tab and variable | PowerShell | |||
| How can I ensure that a variable is a built-in powershell variable? | PowerShell | |||