There are several ways to execute an external process and capture and process its command output in PowerShell.

$OutputVariable = (cmd.exe /c ping localhost) | Out-String

The problem with this short sample is, the stderr is not capture, only the stdout.

With the example below it is possible to capture both outputs.