Reading output from VBScript running powershell command

Viewed 44

I am looping through netstat data using a PowerShell command using Python's subprocess module but that causes PowerShell to flash for half a second and then close repeatedly, making the user experience within my GUI very lackluster. The alternative solution to this problem is to just run a VBScript with the PowerShell command to not display any windows but this comes with the caveat that I am unable to read the output directly from the subprocess.

Right now, writing to a txt file seems to work fine but I am wondering if there is a way to handle this within the subprocess module and read the PowerShell command directly from my VBScript.

Here is what my VBScript looks like:

objShell.Run("powershell.exe -noProfile -executionPolicy -bypass -command ""Get-NetTCPConnection | Group-Object -Property State, OwningProcess | Select -Property Count, Name, @{Name="ProcessName";Expression={(Get-Process -PID ($_.Name.Split(',')[-1].Trim(' '))).Name}}, Group | Sort Count -Descending | Out-File -FilePath .\netstatData.txt""")

I am basically running the aforementioned code using subprocess, writing to a txt file, and then reading the txt which seems very inefficient to me.

0 Answers
Related