How do I capture the output into a variable from an external process in PowerShell?

I’d like to run an external process and capture it’s command output to a variable in PowerShell. I’m currently using this:

$params = "/verify $pc /domain:hosp.uhhg.org"
start-process "netdom.exe" $params -WindowStyle Hidden -Wait

I’ve confirmed the command is executing but I need to capture the output into a variable. This means I can’t use the -RedirectOutput because this only redirects to a file.

11 Answers
11

Leave a Comment