I have created a form to run ipconfig /all on a remote machine via PSEXEC (don’t have remoting enabled in our environment, so I can’t invoke a command). When I run PowerShell script/form locally, the output of the ipconfig /all command shows up in my output box in the form without a problem. However, when I run the script from a share, it quickly opens a cmd window and runs the ipconfig /all command and quickly goes away (does not show output in the output box like it does when run local on the machine). Here is my code (below). The $Output variable shows the output of the command in my output box in the form.
$ButtonAction = $btn8.add_click({ If (!($TextBox.Text)){$TextBox.Text = $env:COMPUTERNAME} If($TextBox.Text -like "*,*"){[array]$TextBoxData = $TextBox.Text.Trim() -split "," -replace '\s',''}Else{$TextBoxData = $TextBox.Text.Trim() -replace '\s',''} foreach ($Computer in $TextBoxData) { $Output = "Current Computer: $Computer`n" | Out-String $OutputBox.AppendText($Output) if(Test-Connection -ComputerName $Computer -Count 2 -Quiet) { $Output = "Running ipconfig /all on $Computer `n" | Out-String $OutputBox.AppendText($Output) Try { If (Test-Path \\SERVER\Scripts\Development\Get-ComputerInfo\psexec.exe -ea stop) { $ipconfig = New-Object System.Diagnostics.ProcessStartInfo $ipconfig.FileName = "\\SERVER\Scripts\Development\Get-ComputerInfo\psexec.exe" $ipconfig.RedirectStandardError = $true $ipconfig.RedirectStandardOutput = $true $ipconfig.UseShellExecute = $false $ipconfig.Arguments = "\\$Computer ipconfig /all" $p = New-Object System.Diagnostics.Process $p.StartInfo = $ipconfig $p.Start() | Out-Null $p.WaitForExit() $stdout = $p.StandardOutput.ReadToEnd() $stderr = $p.StandardError.ReadToEnd() [string]$Output = "$stdout `n" $OutputBox.AppendText($Output) } Else { $Output = "Cannot connect to share that includes psexec. `n" | Out-String $OutputBox.AppendText($Output) } } Catch { $Output = "Error: $($_.Exception.Message)`r`n" | Out-String $OutputBox.AppendText($Output) [string]$Output = "$stderr `n" $OutputBox.AppendText($Output) } } Else { $Output = "$Computer is currently offline.`r`n" | Out-String $OutputBox.AppendText($Output) } } })