question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot pass PowerShell array as `$mylist` to Azure CLI

See original GitHub issue

Related command

az ad app update

Describe the bug

–Using Powershell– Adding a redirect URI to an app is common practice for us. --web-redirect-uris is rather particular with how values are given to it. As of 2.37 with the migration of az ad to Microsoft Graph API, we use the following script to append a single URI to the list and it’s worked pretty well:

$app = az ad app show --id $appId | ConvertFrom-Json
$redirectUris = $app.web.redirectUris
$redirectUris += $newRedirectUri
$redirectUris = $redirectUris | ForEach-Object {"`"$_`""}
az ad app update --id $appId --web-redirect-uris $redirectUris

This has been sufficient until 2.40, where this no longer works. I have not been able to figure out a way to pass multiple URIs in a Powershell variable to --web-redirect-uris.

To Reproduce

Use Az CLI 2.39:

  1. Create a App Registration in AAD. Add two or three redirect URIs. a. I.e., https://site1.example.com/signin-oidc, https://site2.example.com/signin-oidc
  2. Assign a new URI to $newRedirectUri variable (or similar), and run the script snippet.
  3. The command should be successful

$redirectUris should appear like so when printed to console:

"https://site1.example.com/signin-oidc"
"https://site2.example.com/signin-oidc"
"https://site3.example.com/signin-oidc"

Try again with Az CLI 2.40. It no longer works: One or more properties contains invalid values.

Expected behavior

At least in Powershell, each URI must be wrapped in quotes. Double quotes works for us because we’re using vars. This is achieved with line 4 of the script. Each URI must also be space separated as per the documentation. The $redirectUris variable is an array, however Powershell appears to just print out each URI sequentially when the command is run. It behaves like so: az ad app update --id $AppId --web-redirect-uris "https://site1.example.com/signin-oidc" "https://site2.example.com/signin-oidc" "https://site3.example.com/signin-oidc" "https://site4.example.com/signin-oidc" This satisfies the command as of 2.39.

Environment summary

Az CLI 2.40, Windows 11, Powershell 7

Additional context

There does not appear to be any changes to az ad for 2.40 according to the release notes. The --set flag doesn’t appear to be much use either. Perhaps I am using it wrong, but that’s outside of the scope of this issue. (If someone knows how to update redirect URIs using --set, I’d love to know how!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
jiaslicommented, Sep 9, 2022

Sometimes $mylist may contain only one item. @mylist will cause "abc" to be split:

> $mylist = "abc"
> az --debug @mylist
cli.knack.cli: Command arguments: ['--debug', 'a', 'b', 'c']

Instead, use

> $mylist = @("abc")
> az --debug @mylist
cli.knack.cli: Command arguments: ['--debug', 'abc']

See https://docs.microsoft.com/en-us/powershell/scripting/learn/deep-dives/everything-about-arrays?view=powershell-7.2

2reactions
kmkelly2015commented, Sep 9, 2022

Thank you @jiasli , I second what @JackSch said, this has saved us a lot of pain.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure DevOps - Pass Powershell list variable to yml template ...
You are not going here to have an array. Once you assign this to variable it will be a plain string. This is...
Read more >
Everything you wanted to know about arrays - PowerShell
What is an array? I'm going to start with a basic technical description of what arrays are and how they are used by...
Read more >
By Using Batch file copy commented array to powershell script ...
One workaround for this is to use a delimiter character that you can embed in the string that you use for the powershell.exe...
Read more >
Use deployment scripts in templates - Azure Resource Manager
Currently, Azure PowerShell and Azure CLI deployment scripts on the Linux environment are supported. Allow passing command-line arguments to ...
Read more >
A Plethora of PowerShell Pitfalls - Simple Talk
If Get-ChildItem returns more than one item then the type of $myList is an array, which has a Count property, and the conditional...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found