Skip to content

Instantly share code, notes, and snippets.

@LaurentDardenne
Created January 7, 2023 13:55
Show Gist options
  • Save LaurentDardenne/ee911fe73907460b921fd18538b3b448 to your computer and use it in GitHub Desktop.
Save LaurentDardenne/ee911fe73907460b921fd18538b3b448 to your computer and use it in GitHub Desktop.
Set the console output (stdout) to a stream
#from https://github.com/PowerShell/PowerShell/issues/18364#issuecomment-1289401093
$Writer = [System.IO.StreamWriter]::new("$HOME\DemoLog.txt")
$Writer.AutoFlush = $true
$OriginalOut = [System.Console]::Out
try
{
[System.Console]::SetOut($Writer)
[System.Console]::WriteLine("Hello")
}
finally
{
[System.Console]::SetOut($OriginalOut)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment