what trouble I met:

sa@DESKTOP-WEI:~$ az group list --query "[?name != 'product'].name" | jq -c '.[]' | while read g; do     az group delete -n $g --no-wait -y;  don
e
ValidationError: Parameter 'resource_group_name' must conform to the following pattern: '^[-\\w\\._\\(\\)]+$'.

what I've tried :

I tried to print $g value,it looks like just normal string

sa@DESKTOP-WEI:~$ az group list --query "[?name != 'product'].name" | jq -c '.[]' | while read g; do     echo $g; done
"NetworkWatcherRG"
1

There are 1 best solutions below

0
On BEST ANSWER

I don't know why,but I changed to for loop to do it and it's work

sa@DESKTOP-WEI:~$ for rg in $(az group list --query "[?name != 'product'].name" | jq -r '.[]'); \
> do az group delete -n ${rg};\
> done
Are you sure you want to perform this operation? (y/n):

idea from : How to Delete Multiple Azure Resource Groups with Tags, Bash via Azure Cloud Shell, and the Azure CLI | Jon Gallant