powershell - Simple InputBox function -


i'm aware of simple pop-up function powershell, e.g.:

function popup($text,$title) {     $a = new-object -comobject wscript.shell     $b = $a.popup($text,0,$title,0) }  popup "enter demographics" "demographics" 

but unable find equivalent getting pop-up ask input.

sure, there read-line, prompts console.

and there complex function, seems overkill script ask input once or twice:

function getvalues($formtitle, $texttitle){     [void] [system.reflection.assembly]::loadwithpartialname("system.drawing")      [void] [system.reflection.assembly]::loadwithpartialname("system.windows.forms")       $objform = new-object system.windows.forms.form     $objform.text = $formtitle     $objform.size = new-object system.drawing.size(300,200)     $objform.startposition = "centerscreen"      $objform.keypreview = $true     $objform.add_keydown({if ($_.keycode -eq "enter") {$x=$objtextbox.text;$objform.close()}})     $objform.add_keydown({if ($_.keycode -eq "escape") {$objform.close()}})      $okbutton = new-object system.windows.forms.button     $okbutton.location = new-object system.drawing.size(75,120)     $okbutton.size = new-object system.drawing.size(75,23)     $okbutton.text = "ok"     $okbutton.add_click({$script:userinput=$objtextbox.text;$objform.close()})     $objform.controls.add($okbutton)      $cancelbutton = new-object system.windows.forms.button     $cancelbutton.location = new-object system.drawing.size(150,120)     $cancelbutton.size = new-object system.drawing.size(75,23)     $cancelbutton.text = "cancel"     $cancelbutton.add_click({$objform.close()})     $objform.controls.add($cancelbutton)      $objlabel = new-object system.windows.forms.label     $objlabel.location = new-object system.drawing.size(10,20)     $objlabel.size = new-object system.drawing.size(280,30)     $objlabel.text = $texttitle     $objform.controls.add($objlabel)      $objtextbox = new-object system.windows.forms.textbox     $objtextbox.location = new-object system.drawing.size(10,50)     $objtextbox.size = new-object system.drawing.size(260,20)     $objform.controls.add($objtextbox)      $objform.topmost = $true      $objform.add_shown({$objform.activate()})      [void] $objform.showdialog()      return $userinput }  $schema = getvalues "database schema" "enter database schema" 

probably simplest way use inputbox method of microsoft.visualbasic.interaction class:

[void][reflection.assembly]::loadwithpartialname('microsoft.visualbasic')  $title = 'demographics' $msg   = 'enter demographics:'  $text = [microsoft.visualbasic.interaction]::inputbox($msg, $title) 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -