Ignore Powershell progress updates on stderr
Starting with PowerShell 5, the progress bar can be observed via the Write-Progress cmdlet. From WinRM, this appears as a stderr output. Vagrant assumes that there is error if output appears on stderr. This terminates various scripts which previously executed successfully in Vagrant (prior to Windows 10). This fix injects a variable assignment at various points of the script execution process to disable display of the progress bar.
This commit is contained in:
parent
90b850aa49
commit
774940521e
|
@ -212,10 +212,11 @@ module VagrantPlugins
|
|||
file.unlink
|
||||
end
|
||||
|
||||
# convert to double byte unicode string then base64 encode
|
||||
# just like PowerShell -EncodedCommand expects
|
||||
# Convert to double byte unicode string then base64 encode
|
||||
# just like PowerShell -EncodedCommand expects.
|
||||
# Suppress the progress stream from leaking to stderr.
|
||||
wrapped_encoded_command = Base64.strict_encode64(
|
||||
"#{command}; exit $LASTEXITCODE".encode('UTF-16LE', 'UTF-8'))
|
||||
"$ProgressPreference='SilentlyContinue'; #{command}; exit $LASTEXITCODE".encode('UTF-16LE', 'UTF-8'))
|
||||
|
||||
"powershell -executionpolicy bypass -file \"#{guest_script_path}\" " +
|
||||
"-username \"#{shell.username}\" -password \"#{shell.password}\" " +
|
||||
|
|
|
@ -11,6 +11,7 @@ Try {
|
|||
exit $LASTEXITCODE
|
||||
}
|
||||
|
||||
$ProgressPreference = "SilentlyContinue"
|
||||
$task_name = "WinRM_Elevated_Shell"
|
||||
$out_file = "$env:SystemRoot\Temp\WinRM_Elevated_Shell.log"
|
||||
|
||||
|
|
|
@ -54,8 +54,10 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def powershell(command, &block)
|
||||
# ensure an exit code
|
||||
# Suppress the progress stream from leaking to stderr
|
||||
command = "$ProgressPreference='SilentlyContinue';\r\n" + command
|
||||
command << "\r\n"
|
||||
# Ensure an exit code
|
||||
command << "if ($?) { exit 0 } else { if($LASTEXITCODE) { exit $LASTEXITCODE } else { exit 1 } }"
|
||||
execute_shell(command, :powershell, &block)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue