0

I am trying to use a bash variable (ID in the below script) in azure CLI command. but seems its not working and throwing below error:

usage error --scope: must be a fully qualified ARM ID.

The error is happening on line az policy assignment list --scope $ID

I have verified by echoing the ID variable and its outputting correctly which is:

"/providers/Microsoft.Management/managementGroups/test-management-group"

What i am doing wrong here?

Full script is here:

MGS=$(az account management-group list)
for (( i = 0; i < ${#MGS[@]}; i++ )) 
do 
    ID=$(echo $MGS | jq .[$i].id)
    echo $ID
    az policy assignment list --scope $ID
done
Cyrus
  • 84,225
  • 14
  • 89
  • 153
Rezoan
  • 1,745
  • 22
  • 51

1 Answers1

0

The suitable bash script example here:

for id in $(az account management-group list --query [].id -o tsv)
do
    echo "Management Group ID: $id"
    az policy assignment list --scope $id
done
Charles Xu
  • 29,862
  • 2
  • 22
  • 39