I am trying to execute an external command using powershell, without having the second program to popup, I need to execute this program within the same PowerShell window and output both the log and the errors. I started with this:
$outcome = Start-Process -Wait -FilePath "cmd.exe" -ArgumentList "dir" -NoNewWindow 2>&1
$outcome
But it doesn't work as expected. I still see the new window popping up with DOS and no redirect at all about the output, the errors and so on. Am I doing something wrong?
Powershell workflows provide a powerful way to run powershell modules and scripts against multiple servers in parallel.
Using AND(&&) Operator You can use this in both CMD and Powershell. Usage: command1 && command2 && command3 [&& command4 ...]
Does this work for you?
$outcome = Invoke-Expression "cmd.exe /c dir"
$outcome
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With