0

Something very weird is happening while using Azure Command Line Interafce (CLI). I'm writing a PowerShell(PS) script to automate Azure resource creation. Before that I was trying few commands on PowerShell window. Version of PS I'm using is 5.1.17763.134.

Now, first I ran below command:

az account list

Output:

[
 {
    "cloudName": "AzureCloud",
    "homeTenantId": "<deliberately garbled>",
    "id": "<deliberately garbled>",
    "isDefault": false,
    "managedByTenants": [],
    "name": "Visual Studio Enterprise – MPN",
    "state": "Enabled",
    "tenantId": "<deliberately garbled>",
    "user": {
      "name": null,
      "type": "user"
    }
  }
 ]

Here name of my Azure subscription is shown as Visual Studio Enterprise – MPN which is correct.

Then, I ran the same command and put it into a PS variable $accounts as below. Then ran another command to print the value of that variable on the console:

$accounts = az account list
$accounts

Now I get output as shown below:

[
 {
    "cloudName": "AzureCloud",
    "homeTenantId": "<deliberately garbled>",
    "id": "<deliberately garbled>",
    "isDefault": false,
    "managedByTenants": [],
    "name": "Visual Studio Enterprise û MPN",
    "state": "Enabled",
    "tenantId": "<deliberately garbled>",
    "user": {
      "name": null,
      "type": "user"
    }
  }
 ]

Notice the malformed name Visual Studio Enterprise û MPN. It is not able to handle the special charcter hyper (-) in the subscription name. Can someone help what is going wrong? Most of the related posts I read on SO are related to reading/writing files from/to disk but this is happening all in-memory. Possibly it has something to do with encoding but I'm not sure.

Update: JosefZ's comment pointed me in the right direction. I had to configure the terminal encoding as per the screenshot in this answer - https://stackoverflow.com/a/57134096/465053

RBT
  • 24,161
  • 21
  • 159
  • 240
  • Yeah, can you try with `-Encoding UTF8` if `az account list` supports that argument? And not that it should matter, but you're in a English Azure Region? – Jeremy Thompson May 02 '22 at 06:19
  • There is no `-Encoding` parameter for this command. I'm not sure about region. I had an impression region comes into play when we create a resource in Azure. Is an account also associated with a region? How can I check my Azure region from command line or Azure portal if that's the case? – RBT May 02 '22 at 07:03
  • 1
    A simple [mojibake](https://en.wikipedia.org/wiki/Mojibake) case (example in Python): `'–'.encode( 'cp1250').decode( 'cp850')` returns `'û'`. The questionable character is `–` (U+2013, *En Dash*). Configure the terminal encoding (something like `chcp 1250`)? – JosefZ May 02 '22 at 09:11
  • Thank you @JosefZ. You were right. I got my answer here - [Using UTF-8 Encoding (CHCP 65001) in Command Prompt / Windows Powershell (Windows 10)](https://stackoverflow.com/q/57131654/465053) – RBT May 04 '22 at 06:40
  • Hello @RBT Glad that your Issue got resolved could post your findings as an answer so that it would be helpful for other community members – SaiSakethGuduru May 05 '22 at 09:56
  • @SaiSakethGuduru-MT please see the link in the update section of my post. I was able to resolve my issue following that answer. – RBT May 06 '22 at 09:32

0 Answers0