Use HTML form as GUI for powershell

后端 未结 7 1110
北海茫月
北海茫月 2021-02-10 03:57

I have a powershell script that I would like to run using an html form. All I have is a few form fields and a button. When I run my powershell script, it opens a new ie window

7条回答
  •  粉色の甜心
    2021-02-10 04:09

    I was trying to accomplish the same thing and ran across your post. I see it's been about 8 months, but if you're still looking here's what I found. I was not able to get "onclick" to work. So I used a hidden input field, and defined an action for the button to update the value of that field. In powershell I getElementbyId for the hidden field, and use that to recognize the user has completed the input.

    $html = @"
    
    
    
    First name:
    Last name:
    "@ $ie = new-object -com "InternetExplorer.Application" $ie.navigate2("about:blank") $ie.AddressBar = $false $ie.MenuBar = $false $ie.StatusBar = $false $ie.document.body.innerHTML = $html $ie.Visible = $true $doc = $ie.document while ($doc.getElementByID("finished").value -ne 1) { start-sleep -m 500 } $ie.Visible = $false "You answered:" $doc.getElementByID("firstname").value $doc.getElementByID("lastname").value $ie.quit()

提交回复
热议问题