I am updating a Classic ASP webpage. It seems that if you try to use StdIn.Writeline to send command to PowerShell it fails. It behaves like the command interpreter only accepts commands as part of creating the session.
Does anyone have any working examples of passing supplemental commands to an open PowerShell execution from a Classic (Not ASP.Net) web page?
Command = "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Powershell.exe -NoExit -inputformat none -ExecutionPolicy bypass -NonInteractive -noprofile -Command ""& {""$PSVersionTable.PSVersion""; ""Add-PSSnapIn VMware* -ErrorAction SilentlyContinue""; 2>&1} "
Set oExec = WshShell.Exec(Command)
If oExec.Status = 0 Then
oExec.StdIn.Writeline("Dir 2>&1")
oExec.StdIn.Writeline("Exit")
oExec.StdIn.Close()
Do While oExec.StdOut.AtEndOfStream <> True
Response.Write oExec.StdOut.ReadLine
Loop
End If
When I try to keep the command interpreter open and use StdIn.Writeline
to send additional commands, including the exit command, it never closes and I have to kill the process on the IIS server.
If I remove the -NoExit
switch, it does close after running the string passed, and obviously I can't send additional commands to run.
Any ideas on how to get PowerShell to work like %comspec%
does?