Search code examples
azurepowershellshellazure-aks

How to use use double quotes to avoid the unrecognized arguments: containers ][*].image}


How to avoid the unrecognized arguments having issues with the quotes usage

az aks command invoke --resource-group test-shared-dev --name  test-aks-dev --command "kubectl get pods --all-namespaces -o jsonpath= `"{.items[*].spec['initContainers', 'containers'][*].image}`""

enter image description here


Solution

  • To resolve this issue, you'll need to modify the command so that it handles the quoting and piping correctly. Here's an updated version of the command that avoids syntax issues by using escaped quotes for nested commands. First part I have already updated in comment section.

    For the additional sorting, use this-

    az aks command invoke --resource-group arkorg --name arko-cluster1 --command "kubectl get pods --all-namespaces -o jsonpath='{.items[].spec.containers[].image} {.items[].spec.initContainers[].image}' | tr -s '[[:space:]]' '\n' | sort | uniq -c"
    

    enter image description here

    works on powershell as well

    enter image description here

    References: