Automation

 View Only
  • 1.  How to get specific user input from the script

    Posted Oct 21, 2010 04:17 PM

    Hello:

    I’m wondering if it’s possible to get specific user input.

    I know I can write something like

    $input = Read-Host "Type information” , but I want to give specific options.

    Basically, I want to ask a question and give two options “yes” (script will continue) and “no” (script will stopped).

    Is there a way to do it?

    Thanks a lot!



  • 2.  RE: How to get specific user input from the script
    Best Answer

    Posted Oct 21, 2010 04:50 PM

    You could do

    $input = ""
    while("yes","no" -notcontains $input){
      $input = Read-Host "Enter yes to continue, no to stop”
    }
    

    ____________

    Blog: LucD notes

    Twitter: lucd22



  • 3.  RE: How to get specific user input from the script

    Posted Oct 21, 2010 05:25 PM

    Luc,

    Thank you very much for your help.

    Ideally I would like to see the buttons "yes" and "no", but this option would work, too.

    Thanks again for your help.



  • 4.  RE: How to get specific user input from the script

    Posted Oct 21, 2010 08:19 PM
      |   view attached

    If you want to have buttons you will have to use

    $Input = [http://Windows.Forms.MessageBox|http://Windows.Forms.MessageBox]::Show("Stop the script", "My script",
    	[http://Windows.Forms.MessageBoxButtons|http://Windows.Forms.MessageBoxButtons]::YesNo,
    	[http://Windows.Forms.MessageBoxIcon|http://Windows.Forms.MessageBoxIcon]::Question)
    if($Input -eq [http://Windows.Forms.DialogResult|http://Windows.Forms.DialogResult]::Yes){exit}
    

    I attached the script since the forum SW has problems with square brackets.

    ____________

    Blog: LucD notes

    Twitter: lucd22

    Attachment(s)

    ps1
    Ok-Cancel-button.ps1   219 B 1 version


  • 5.  RE: How to get specific user input from the script

    Posted Oct 25, 2010 06:20 PM

    Luc,

    Thank you very much! It's exactly what I was looking for!

    Thanks a lot!