Please feel free to provide feedback or file bugs here.

Start-Process EncodedCommand (RedirectStandardError) v5.1

The following script demonstrates an issue I'm experiencing after moving from PowerShell v4 to v5.1. I make extensive use of Start-Process redirecting StandardError to a file, if this file contains data after execution I can read the file to see what the issue was.

However, with v5.1 when the launched PowerShell process starts, it makes use of progress output which is on the error stream, so this is redirected to the error file.

In previous versions of PowerShell this did not happen.

The output to the script below is as follows:

Powershell v4
------------------
WARNING: Standard Error
WARNING: Standard Out
hello world!

Powershell v5.1
---------------------
WARNING: Standard Error

SourceId Record
-------- ------
1 parent = -1 id = 0 act = Preparing modules for first use. stat = cur = pct = -1 sec = -1 type = Completed
hello world!

WARNING: Standard Out
hello world!

# ------------------------------------- Script Start

$outfile = [System.IO.Path]::GetTempFileName()
$errorfile = [System.IO.Path]::GetTempFileName()

$command = "write-host 'hello world!'"
$encodedCommand = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($command))
$argumentList = @(
"-NoLogo",
"-NonInteractive",
"-NoProfile",
"-EncodedCommand",
$encodedCommand
)

Start-Process powershell `
-argumentlist $argumentList `
-PassThru `
-wait `
-RedirectStandardOut $outfile `
-NoNewWindow `
-RedirectStandardError $errorfile | Out-Null

Write-Warning "Standard Error"
try {
Import-Clixml $errorfile | Out-Host
}
catch {
Get-Content $errorfile
}

Write-Warning "Standard Out"
Get-Content $outfile

$outfile, $errorfile | Remove-item

1 vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)

    We’ll send you updates on this idea

    David Martin shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    1 comment

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base