liet Posted September 14, 2017 Share Posted September 14, 2017 I am looking for a way to automate an interactive PowerShell script. In essence, it writes some data to the screen using the write-host cmdlet and then wait for keyboard input. I would like to be able to either run the PS script via AutoIT or run the PS script separately and make AutoIT focus on the window. I can handle the input part using Send function, but I can't seem to be able to read the content of the window. So far I have tried with StdoutRead, ConsoleRead and WinGetText, but I can't seem to be able to pull any text from the console window. If anyone has done something like this before, I would very much welcome the help with my problem. Link to comment Share on other sites More sharing options...
Developers Jos Posted September 14, 2017 Developers Share Posted September 14, 2017 Please show your code that you used with STDOutRead() so we can see whether that looks correct. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
junkew Posted September 14, 2017 Share Posted September 14, 2017 @ptrex can maybe answer as based on clr.au3 we have achieved a lot of powershell integration but also have impediment on getting objects returned processed in AutoIt see also FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
liet Posted September 14, 2017 Author Share Posted September 14, 2017 1 hour ago, Jos said: Please show your code that you used with STDOutRead() so we can see whether that looks correct. Jos It goes something like this: Local $iPID = Run('PowerShell.exe -executionpolicy Bypass -File "C:\Users\QKXC64\Desktop\script.ps1"') Local $sOutput For $i = 200 To 1 Step -1 $sOutput &= StdoutRead($iPID) Sleep(25) Next MsgBox($MB_SYSTEMMODAL, "", "Received: " & @CRLF & @CRLF & $sOutput) Link to comment Share on other sites More sharing options...
Developers Jos Posted September 14, 2017 Developers Share Posted September 14, 2017 53 minutes ago, liet said: It goes something like this: Something like this huh... Well that's not going to work as you clearly missed some parameter there.. just look at the example in StdOutRead(). Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 14, 2017 Moderators Share Posted September 14, 2017 I have been playing around with this, as I am doing a lot with PowerCLI right now for managing VMware environments. You might think about wrapping it in a child GUI, like so (simple example): expandcollapse popup#include <GUIEdit.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Local $hGUI_Main, $hGUI_Child, $sPing, $sText = "", $editProgress $hGUI_Main = GUICreate("Powershell Test", 300, 150) $btnExit = GUICtrlCreateButton("Exit", 10, 100, 80, 30) $btnGo = GUICtrlCreateButton("Execute", 200, 100, 80, 30) GUISetState(@SW_SHOW) _Create_Child($hGUI_Main) GUIRegisterMsg($WM_MOVE, "_Position_Child") While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE, $btnExit Exit Case $btnGo $sPing = "Ping www.Google.com" _SH_Child($hGUI_Main, $btnGo) Sleep(500) _execute() EndSwitch WEnd GUIDelete() Func _execute() $sCMD = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command " & $sPing $pid = Run($sCMD, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD) StdinWrite($pid) $sSTDOUT = "" While 1 $sOutput = StdoutRead($pid) If @error Then ExitLoop If $sOutput <> "" Then $sText &= $sOutput & @CRLF _GUICtrlEdit_AppendText($editProgress, $sText) EndIf WEnd EndFunc Func _Create_Child($hGUI_Main) $hGUI_Child = GUICreate("Follower", 600, 625, -1, -1, BitOR($WS_POPUP, $WS_BORDER), 0, $hGUI_Main) $editProgress = GUICtrlCreateEdit($sText, 1, 1, 598, 624, BitOR($WS_VSCROLL, $ES_READONLY, $ES_AUTOVSCROLL)) GUISetFont(11, 400, Default, "Arial") _Position_Child($hGUI_Main, 0, 0, 0) GUISetState(@SW_HIDE, $hGUI_Child) EndFunc Func _Position_Child($hWnd, $iMsg, $wParam, $lParam) If $hWnd <> $hGUI_Main Then Return Local $aGUI_Main_Pos = WinGetPos($hGUI_Main) WinMove($hGUI_Child, "", $aGUI_Main_Pos[0] + $aGUI_Main_Pos[2] + 2, $aGUI_Main_Pos[1]) EndFunc Func _SH_Child($hGUI_Main, $btnGo) If GUICtrlRead($btnGo) = "Execute" Then GUISetState(@SW_SHOW, $hGUI_Child) GUICtrlSetData($btnGo, "Back") WinActivate($hGUI_Main) Else GUISetState(@SW_HIDE, $hGUI_Child) GUICtrlSetData($btnGo, "Execute") EndIf EndFunc "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
ptrex Posted September 14, 2017 Share Posted September 14, 2017 So far using the CLR.au3 automation there is no descend way to get the data transfer in the console... The only workaround for the moment is to output to Clipboard... and read this back into AutoIT... I have been reading half the internet and not found a structural solution... https://www.howtogeek.com/163127/how-powershell-differs-from-the-windows-command-prompt/ Quote ...automate an interactive PowerShell script. In essence, it writes some data to the screen using the write-host cmdlet and then wait for keyboard input .... I just tested the "ActiveXPoSH" COM object running a Parameter Function that has a mandatory Parameter input... and this COM Object support BI-Directional input. The PowerShell script is paused untill the parameter is entered... function Something { Param ( [Parameter(Mandatory=$true, Position=0)] [string] $Name ) write-host "Output : $Name " } Something Here is an Example in combination of ActiveXPoSH and VMWare https://stujordan.wordpress.com/tag/powershell/ Hope this helps... Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
junkew Posted September 15, 2017 Share Posted September 15, 2017 Quote "I have been reading half the internet and not found a structural solution..." Then the answer must be in the other half. so far I didn't find it either but also no statements found its not possible https://www.google.nl/search?q=powershell+pipe+to+stdouthttps://www.google.nl/search?q=powershell+kills+stdout FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
ptrex Posted September 15, 2017 Share Posted September 15, 2017 There's a lot to read, but not really relevant .... All of the examples found and discussed are using C# code intermediate solutions... which we are not looking for. I am trying to find a AU3 native solution so we are not depending on anything else... If not, I we could as well keep on using the "ActiveXPoSH" Com object... which can handle anything even parameter scripts as you can see ... Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now