0

I used the below command to list and stop all the VMs in my account. VMs are listing, but an additional STDIN is getting listed. This STDIN is causing the error "invalid resource id"

What can I do to ignore the STDIN??. Your help greatly appreciated.

az vm stop --ids $(az vm list --query "[].id" -o tsv) | grep -v "ABDK" 

thanks

2
  • Try az vm stop --ids $(az vm list --query "[].id" -o tsv) | grep -v "ABDK" ?
    – Nancy
    Jan 29, 2021 at 2:01
  • @NancyXiong My bad, I missed the | while asking question. Actually, we have it. Still the same error.
    – Mangaraju
    Jan 29, 2021 at 6:55

1 Answer 1

0

If you mean the VM name by the STDIN and want to stop all the VMs that the name does not contain the string ABDK, then you can use the CLI command only like this:

az vm stop --ids $(az vm list --query "[?contains(@.name, 'ABDK')==\`false\`].id" -o tsv)

Update:

If you run the CLI command in the Windows PowerShell, then you need to change the command like this:

az vm stop --ids $(az vm list --query "[?!contains(@.name, 'ABDK')].id" -o tsv)
4
  • I'm facing this error with this command InvalidArgumentValueError: argument --query: invalid jmespath_type value: "[?contains(@.name, 'ABDK')==\`false\`].id"
    – Mangaraju
    Jan 29, 2021 at 7:17
  • @Mangaraju Do you run the CLI command in Windows PowerShell? It yes, then you need to change the command like the update.
    – Charles Xu
    Jan 29, 2021 at 7:49
  • Thanks @Charles Xu Now it is giving the list correctly. By EOD I will try this for stopping the VMs and update you again. thanks again
    – Mangaraju
    Jan 29, 2021 at 10:52
  • @Mangaraju Well, if it works for you please accept it.
    – Charles Xu
    Feb 1, 2021 at 1:36

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.