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