Azure CLI and PowerShell 7.3 OutputEncoding issue
10:17 16 Feb 2024

There are two different commands run in my PowerShell 7.3 within Windows Terminal.

  1. Just run the az devops user show command.

    az devops user show --user $UserPrincipalName -o json
    

    enter image description here

  2. Run the same command with a $(...).

    $(az devops user show --user $UserPrincipalName -o json)
    

    enter image description here

It because my user info contains Chinese characters. The first command will be able to show correct Chinese characters. The seconds command will show garbled text on the screen.

With the same commands, if I run in my Windows PowerShell 5.1, it display the Chinese characters perfectly. Why?

What's the difference between these two commands? How to display the Chinese characters correctly on the screen when running the second command in PowerShell 7.3?

Edit

I tried to run this before run my second command. Then the output display Chinese characters correctly.

[Console]::OutputEncoding = [System.Text.Encoding]::GetEncoding('big5')

Is there any way I can force az command output using utf8 encoding?

powershell azure-devops azure-powershell azure-cli powershell-7.3