Use HTML form as GUI for powershell

后端 未结 7 1135
北海茫月
北海茫月 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:07

    I add javascript by using the execScript("SCRIPT HERE","Type Of Script") of the parent window

    $html = @"
    
        
            
    First name:
    Last name:
    "@ $ie = new-object -com "InternetExplorer.Application" $ie.navigate("about:blank") $ie.document.body.innerHTML = $html $doc = $ie.Document $doc.parentWindow.execScript("document.getElementById('finished').onclick = function(){document.getElementById('finished').value = 'Submitted';};","javascript") $ie.Visible = $true while ($doc.getElementByID("finished").value -ne "Submitted") { start-sleep -m 500 $firstName = $doc.getElementByID("firstname").value $lastName = $doc.getElementByID("lastname").value } $ie.Visible = $false "You answered:" $doc.getElementByID("firstname").value $doc.getElementByID("lastname").value $ie.quit()

提交回复
热议问题