capture cmd output and display in textbox

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
jack_jones
Posts: 1
Last visit: Sun Jun 20, 2021 10:38 am

capture cmd output and display in textbox

Post by jack_jones »

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: powershell studio 2021
Operating system: windows 10
PowerShell version(s): 5.1
32-bit version of software? no

I'm trying to convert existing working code into powershell studio.
$ComputerName = $InputBox2.text;
$psx =Join-Path $PSToolsPath Psexec64.exe
$results = & $psx -accepteula -nobanner \\$ComputerName netstat -an
foreach($r in $results)
{

$outputBox.Appendtext(("$r") + ("`r`n"))
}

problem is that when i run this in powershell studio the command opens a cmd window runs the netsta -an but the output is not in the $results variable so i cannot send it to the $outputBox. This works in my original script. I suspect its because a cmd window is opening and the output is lost somewhere. Any Ideas how i can capture the result ?

DO NOT POST LICENSES, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

User avatar
brittneyr
Site Admin
Posts: 818
Last visit: Fri Jul 30, 2021 12:06 pm
Answers: 16
Been upvoted: 13 times

Re: capture cmd output and display in textbox

Post by brittneyr »

[Topic moved by moderator to PowerShell GUIs forum]
Brittney Ryn
SAPIEN Technologies, Inc.

User avatar
Alexander Riedel
Posts: 7719
Last visit: Sat Jul 31, 2021 12:28 pm
Answers: 4
Been upvoted: 10 times

Re: capture cmd output and display in textbox

Post by Alexander Riedel »

Looks like you are missing the Out-String
This might help:

https://jackgruber.github.io/2018-05-11 ... ss-output/
Alexander Riedel
SAPIEN Technologies, Inc.

Locked