Moderators JLogan3o13 Posted October 9, 2017 Moderators Posted October 9, 2017 Just a curiosity question, which is why I am not posting anything runnable. I know several of you have been doing some great work marrying AutoIt and PowerShell, and am just curious what you are doing in this regard. I find myself running almost exclusively in PowerCLI lately, as 99% of my contracts are for virtualization tasks. I fall back on AutoIt for anything that requires a GUI (of course!) because I don't have the patience for GUIs in pure PS. One thing I have noticed is returning output from the PowerShell script. At present I am just using the old StdoutRead method: Local $sPSScript = @ScriptDir & "\Launch.ps1" Local $sText = "", $sSTDOUT = "" Local $sCMD = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command . '" & $sPSScript & "'" Local $pid = Run($sCMD, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD) StdinWrite($pid) While 1 $sOutput = StdoutRead($pid) If @error Then ExitLoop If $sOutput <> "" Then $sText &= $sOutput _GUICtrlEdit_AppendText($editProgress, $sText) EndIf WEnd As the script runs it outputs to the edit field. However, I am continually appending said field so my output is duplicated. For example, a PowerCLI script to connect to 4 vCenter servers returns output like so: Quote Name Port User Name Port User ---- ---- ---- mycompany-vc02.mycompany.com 443 mycompany\sa871022 Name Port User ---- ---- ---- mycompany-vc02.mycompany.com 443 mycompany\sa871022 mycompany-vs01mgt01.mycompany... 443 mycompany\sa871022 Name Port User ---- ---- ---- mycompany-vc02.mycompany.com 443 mycompany\sa871022 mycompany-vs01mgt01.mycompany... 443 mycompany\sa871022 mycompany-vs01mgt01.mycompany... 443 mycompany\sa871022 Name Port User ---- ---- ---- mycompany-vc02.mycompany.com 443 mycompany\sa871022 mycompany-vs01mgt01.mycompany... 443 mycompany\sa871022 mycompany-vs01mgt01.mycompany... 443 mycompany\sa871022 mycompany-vsvc02.mycompany... 443 mycompany\sa871022 Name Port User ---- ---- ---- mycompany-vc02.mycompany.com 443 mycompany\sa871022 mycompany-vs01mgt01.mycompany... 443 mycompany\sa871022 mycompany-vs01mgt01.mycompany... 443 mycompany\sa871022 mycompany-vsvc02.mycompany... 443 mycompany\sa871022 Name Port User ---- ---- ---- mycompany-vc02.mycompany.com 443 mycompany\sa871022 mycompany-vs01mgt01.mycompany... 443 mycompany\sa871022 mycompany-vs01mgt01.mycompany... 443 mycompany\sa871022 mycompany-vsvc02.mycompany... 443 mycompany\sa871022 Just curious if anyone is doing any different; the duplication of output gets to be tedious when dealing with longer scripts. "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!
ptrex Posted October 10, 2017 Posted October 10, 2017 One the things you can do is using the famous Out-Gridview -Passthru output to get the data in a more structured way. So you don't need to build any extra GUI ;-) Once you run it you can see the Grid View popping up and use that that for filtering etc... 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
Moderators JLogan3o13 Posted October 10, 2017 Author Moderators Posted October 10, 2017 (edited) Thanks, I thought about that as well. I can get all the data in a single window if I wrap it all in a function and the just output the function to GridView. The problem I encounter is when you're returning different objects and values. For example, in the first part of the function I connect to a several vCenter Servers: $hosts = @( "vCenter01", "vCenter02", "vCenter03", "vCenter04" ) $cred = Get-Credential Connect-VIServer -Server $hosts -Credential $cred Output to GridView looks good, auto-generated columns for Server, Port. and User. However if I do another call like a Get-VirtualPortGroup, GridView doesn't know what to do with the different return types and columns, so it ends up changing to just two columns, Value and Type. For anything that returns more than one value (everything) this cuts off the majority of what gets returned. I am playing around with another function to take in the text from stdout in blocks, remove any duplicate lines, then pass to the Edit control. If it doesn't cause too much of a lag, this may be the way I have to go. Edited October 10, 2017 by JLogan3o13 "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!
paradox109 Posted May 30, 2020 Posted May 30, 2020 The problem is here: $sText &= $sOutput _GUICtrlEdit_AppendText($editProgress, $sText) You reading new line and combining with old stuff and then appending. (Every single time) Local $sPSScript = @ScriptDir & "\Launch.ps1" Local $sText = "", $sSTDOUT = "" Local $sCMD = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command . '" & $sPSScript & "'" Local $pid = Run($sCMD, @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD + $STDERR_CHILD) StdinWrite($pid) While 1 $sOutput = StdoutRead($pid) If @error Then ExitLoop If $sOutput <> "" Then _GUICtrlEdit_AppendText($editProgress, $sOutput) EndIf WEnd Skeletor 1
Moderators JLogan3o13 Posted May 31, 2020 Author Moderators Posted May 31, 2020 @paradox109 typically people aren't still looking for an answer after 3 years, so we tend to frown on necroposting. Thanks though, maybe someone will wander along and find benefit. "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!
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