Addressed in the GitHub issue #11104.
PowerShell 7.3.0 or above supports the -Encoding
parameter that takes one of ASCII
, BigEndianUnicode
, OEM
, Unicode
, UTF7
, UTF8
, UTF8BOM
, UTF8NoBOM
(default), and UTF32
.
NAME
Tee-Object
SYNTAX
Tee-Object [-FilePath] <string> [-InputObject <psobject>] [-Append] [-Encoding <Encoding>] [<CommonParameters>]
Tee-Object -LiteralPath <string> [-InputObject <psobject>] [-Encoding <Encoding>] [<CommonParameters>]
Tee-Object -Variable <string> [-InputObject <psobject>] [<CommonParameters>]
ALIASES
tee
REMARKS
Get-Help cannot find the Help files for this cmdlet on this computer. It is displaying only partial help.
-- To download and install Help files for the module that includes this cmdlet, use Update-Help.
-- To view the Help topic for this cmdlet online, type: "Get-Help Tee-Object -Online" or
go to https://go.microsoft.com/fwlink/?LinkID=2097034.
Even with that flag, it might still be garbled due to how PowerShell parses pipe outputs. See #17523.
@jbobrean93: PowerShell relies on System.Diagnostics.Process
to parse the output from a pipe and in the absence of an explicit setting of the Standard*Encoding
property in the start info it will rely on the global setting of Console.OutputEncoding
to determine what encoding is used. On Windows the default console encoding is still whatever the OS is configured to, which is typically 431 on English hosts. Unfortunately your only workaround here is to set [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
and then run your command.
The command to use
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
YOUR_COMMAND_HERE | Tee-Object -FilePath YOUR_OUTPUT_FILE -Encoding UTF8NoBOM
Notes
You might want to update your PowerShell to use this feature. Use
$PSVersionTable
to check the version of your PowerShell.