New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$ character in az uri string being interpreted by powershell as a command #20686
Comments
The problem is that the When PowerShell rebuilds the process command line behind the scenes it decides which arguments to double-quote strictly based on whether a given argument contains spaces. Thus, any space-less argument that happens to contain # -> 'b' is not recognized as an internal or external command, operable program or batch file.
cmd /c echo 'a&b'
# -> OK
cmd /c echo '"a&b"' Therefore: $t = az rest --uri '"https://management.azure.com/subscriptions/d904052e-5309-4000-9a3f-XXXXXXXXX/resourceGroups/plt-XXXXX-dev-rg-01/providers/Microsoft.Authorization/roleManagementPolicies?api-version=2020-10-01&$filter=asTarget()"' See also: |
@mklement0 thanks very much for your detailed explanation. What confused me was why running command without "$x = ..." worked fine but makes perfect sense with your explanation. I can confirm your suggestion works perfectly. Thank you. |
📣 Hey @abelal83, how did we do? We would love to hear your feedback with the link below! 🗣️ 🔗 https://forms.office.com/r/P926k48jRJ |
Glad to hear it helped, @abelal83. I should mention that the Should the Azure CLI ever move away from a batch-file entry point, the workaround will break. A future-proof alternative is to call via $t = cmd /c 'az rest --uri "https://management.azure.com/subscriptions/d904052e-5309-4000-9a3f-XXXXXXXXX/resourceGroups/plt-XXXXX-dev-rg-01/providers/Microsoft.Authorization/roleManagementPolicies?api-version=2020-10-01&$filter=asTarget()"' Small caveat: If you explicitly set This highlights the general problems with
|
Prerequisites
Steps to reproduce
When assigning output of an AZ cli rest command where URI contains a $ symbol powershell attempts to parse the value of $, even though the string is in quoted with single quotes.
Expected behavior
$t = az rest --uri 'https://management.azure.com/subscriptions/d904052e-5309-4000-9a3f-XXXXXXXXX/resourceGroups/plt-XXXXX-dev-rg-01/providers/Microsoft.Authorization/roleManagementPolicies?api-version=2020-10-01&$filter=asTarget()'
Actual behavior
Error details
Environment data
Visuals
When I run just the below in powershell it works fine, but obviously I'm not assigning return value to anything.
az rest --uri 'https://management.azure.com/subscriptions/d904052e-5309-4000-9a3f-XXXXXXXXX/resourceGroups/plt-XXXXX-dev-rg-01/providers/Microsoft.Authorization/roleManagementPolicies?api-version=2020-10-01&$filter=asTarget()'
The text was updated successfully, but these errors were encountered: