Private/Get-ProcessOutput.ps1
function Get-ProcessOutput { [CmdletBinding()] param ( [Parameter(Mandatory=$true)] [string] $Path, [Parameter()] [string[]] $Arguments ) $process = New-Object System.Diagnostics.Process $process.StartInfo.UseShellExecute = $false $process.StartInfo.RedirectStandardOutput = $true $process.StartInfo.RedirectStandardError = $true $process.StartInfo.FileName = $Path if($Arguments) { $process.StartInfo.Arguments = $Arguments } $null = $process.Start() [pscustomobject]@{ StandardOutput = $process.StandardOutput.ReadToEnd() StandardError = $process.StandardError.ReadToEnd() ExitCode = $process.ExitCode } $process.Dispose() } |