This would be more like a feature request, or at least so far I have not seen a way to do this. Basically it would be nice to be able to query VM's by its status and then doing actions on them, for instance, a common example would be, query all running VM's on a given resource group and stop/deallocate them all.
Install Method: How did you install the CLI? (e.g. pip, interactive script, apt-get, Docker, MSI, nightly)
Answer here: using cli on OSX with docker as well as the portal built-in CLI
CLI Version: What version of the CLI and modules are installed? (Use az --version
)
Answer here:
zure-cli (2.0.10)
acr (2.0.8)
acs (2.0.10)
appservice (0.1.10)
batch (3.0.3)
billing (0.1.3)
cdn (0.0.6)
cloud (2.0.6)
cognitiveservices (0.1.6)
command-modules-nspkg (2.0.1)
component (2.0.6)
configure (2.0.10)
consumption (0.1.3)
container (0.1.5b2+dev)
core (2.0.11+dev)
cosmosdb (0.1.10)
dla (0.0.10)
dls (0.0.10)
feedback (2.0.6)
find (0.2.6)
interactive (0.3.6)
iot (0.1.9)
keyvault (2.0.8)
lab (0.0.8)
monitor (0.0.8)
network (2.0.10)
nspkg (3.0.1)
profile (2.0.8)
rdbms (0.0.5)
redis (0.2.7)
resource (2.0.10)
role (2.0.8)
sf (1.0.5)
sql (2.0.7)
storage (2.0.10)
vm (2.0.10)
Python (Linux) 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609]
Python location '/usr/bin/python'
OS Version: What OS and version are you using?
Answer here: OSX 10.12 / Azure Portal
Shell Type: What shell are you using? (e.g. bash, cmd.exe, Bash on Windows)
Answer here: bash
you can leverage -d
flag., e.g. az vm list -d --query "[?powerState=='VM running']"
Since -d
param includes the column powerState, you have to use it. But the command result may contain lots of unwanted data/columns.
You can select which colums you want to see;
By using following parameters you can get only the name and powerState values:
az vm list --query "[[?powerState=='VM running'].name, [?powerState=='VM running'].powerState]" -d -o table
Most helpful comment
you can leverage
-d
flag., e.g.az vm list -d --query "[?powerState=='VM running']"