I have a script that deallocates all VMs in the subscription based on the tags assigned - off hours and start them back up the next day using Jenkins. I want to be able to query these VMs based on the state (Running/Stopped(deallocated) and output it to a file.
Startup command - az vm start --ids $(az resource list --tag Restart=${TAG_RESTART} --query "[?type=='Microsoft.Compute/virtualMachines'].id" -o table)
Query command -
az resource list --tag Restart=yes --query "[].{Name:name,Group:resourceGroup,Location:location}" -o table
This command returns output (Name, RG and location). I want it to also show the powerstate and possibly OS type once the restart script is complete. If it is also possible to export the output to a spreadsheet.
az vm list --ids $(az resource list --tag Restart='yes' --query "[].{Name:name,Group:resourceGroup,Location:location,PowerState:powerState=='running'}" -o table)
Got this erroraz : ERROR: az: error: unrecognized arguments: --ids Name Group Location ------------- ------------- ---------- hazrnv000er01 dvops-prod-rg eastus At line:1 char:1 + az vm list --ids $(az resource list --tag Restart='yes' --query "[].{ ... + CategoryInfo : NotSpecified: (ERROR: az: erro...prod-rg eastus:String) [], RemoteExcepti on + FullyQualifie..
– bonafide