Azure / Azure/azure-cli

[Shell] Azure CLI receives corrupted arguments in PowerShell

Open
#15,529 8 comments 3 reactions 1 assignee Claimed by @jiasli View on GitHub
common issue Service Attention Shell - PowerShell
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

## Describe the bug

When invoking `az` in PowerShell, due to the known issue of PowerShell https://github.com/PowerShell/PowerShell/issues/1995, arguments passed to Azure CLI may get corrupted. For example, literal double quotes (`"`) are lost:

```pwsh
# PowerShell
> az '{"signInAudience":"AzureADAndMicrosoftAccounts"}' --debug
Command arguments: ['{signInAudience:AzureADAndMicrosoftAccounts}', '--debug']
```

This contradicts the behavior of Bash:

```sh
# Bash
$ az '{"signInAudience":"AzureADAndMicrosoftAccounts"}' --debug
Command arguments: ['{"signInAudience":"AzureADAndMicrosoftAccounts"}', '--debug']
```

## Impact

This is mainly affecting

- passing JSON as an argument as in `az rest --body {JSON}` (#15512)
```powershell
# not working
az rest ... --body '{"signInAudience":"AzureADandPersonalMicrosoftAccount"}'
# working
az rest ... --body '{\"signInAudience\":\"AzureADandPersonalMicrosoftAccount\"}'
```
- using JMESPATH `--query` (#13152)
```powershell
# not working
az version --query '"azure-cli"'
# working
az version --query '\"azure-cli\"'
```

## Workaround

See https://github.com/Azure/azure-cli/blob/dev/doc/quoting-issues-with-powershell.md

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.