How can you find the size of an existing VM using the Azure CLI? I can see how to find what sizes are available, or what sizes a VM can be resized to, but not simply what the existing size is. You'd think that might be one of the details in az vm show --show-details but it's not.
In the screenshot in my comment, I use the command.
az vm show -g '<resource group name>' -n '<VM name>' -d
You could use --query 'hardwareProfile.vmSize' to get the vmSize directly.
az vm show -g '<resource group name>' -n '<VM name>' --query 'hardwareProfile.vmSize' -o tsv
Just as additional info, when using
az vm show -g <resourcegroupname> -n <vmname>
you can see which info is available to access.
For the VMSize you would notice in the responsetree:
JSONResponse
Which you can then access by using the query posted by Joy Wang.
Related
I am running a script that requires the resource group and name of current AKS client config. Previously configured with az aks get-credentials ...
Current script:
(I type AKS=something and RG=SOMETHING before running)
az aks update -g $RG -n $AKSNAME ...
Wanted script:
(I type nothing before running)
AKSNAME=$(what goes here?)
RG=$(what goes here?)
az aks update -g $RG -n $AKSNAME ...
How can I load RG and AKSNAME values automatically through a shell script?
EDIT: I current assign the values to those variables by hand. I want the script to find the values automatically, corresponding to the cluster in the current context e.g. which kubectl is using.
If you just get the credential via the command az aks get-credentials .... without parameter --admin, then you can get the cluster name like this:
AKSNAME=$(kubectl config current-context)
And if you use the parameter --admin, then you need to change the command like this:
AKSNAME=$(kubectl config view --minify -o jsonpath='{.contexts[0].context.cluster}')
Then you can get the group name like this:
RG=$(az aks list --query "[?name == '$AKSNAME'].resourceGroup" -o tsv)
I am looking to get the name of the VM family of a specific VM type via the az cli.
Sample input:
Standard_D16ds_v4
Sample output:
Standard DDSv4 Family vCPUs
Is this possible to do either via az cli or azure RM?
You can use this one,
az vm show -g 'YourResourceGroupName' -n 'VMName' --query 'hardwareProfile.vmSize' -o tsv
You can use the list-skus subcommand to find this:
$ az vm list-skus --size Standard_D16ds_v4 --query [].family
[
"standardDDSv4Family"
]
https://learn.microsoft.com/en-us/cli/azure/vm?view=azure-cli-latest#az-vm-list-skus
I'm trying to list all unmanaged disks in a specific resource group in my account inside Azure cloud provider that not have a specific tag, but having issues with the query part.
The command above lists all unmanaged disks:
az disk list -g $rgName --query [?managedBy=='null'].name -o tsv
When writing the command above, I'm not getting any output (although I have unmanaged disks that don't have tags.Action equals to 'ToDelete':
az disk list -g $rgName --query "[?(managedBy=='null') && (tags.Action!='ToDelete')].name" -o tsv
Thank you for the help :)
I believe the issue is because you are comparing against the string 'null' instead of null. This will cause you to recieve an empty array [] as the result.
This works for me:
az disk list -g $rgName --query "[?(managedBy==null) && (tags.Action!='ToDelete')].name"
I am working on bash shell. I need az cli or unix script to find out NIC name attached to particular VM. I know VM name and VM Resource Group Name and my Target is to findout out which NIC is attached to this VM and which resouce group this NIC belongs to?
Please follow this line of azure cli code:
Step 1: Define a variable, like a. Note that there is no whiteSpace around the chars = :
a="$(az vm nic list --resource-group "your_resource_group" --vm-name "your_vm_name" --query "[].{id:id}" --output tsv)"
Step 2: Just get the nic name and it's resource group:
az vm nic show -g "your_resource_group" --vm-name "your_vm_name" --nic $a --query "{name:name,resourceGroup:resourceGroup}" --output table
Step 3: If you want get all the information of nic, please use the code below:
az vm nic show -g "your_resource_group" --vm-name "your_vm_name" --nic $a
az vm nic list --resource-group
--vm-name
[--subscription]
This will list all nics on a vm.
eg. az vm nic list -g MyResourceGroup --vm-name MyVm
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.
You could use az vm show -d --ids to get powershell state.
Sorry, I don't have a Mac VM. On Linux VM, I use the following command to get it.
az vm show -d --ids $(az resource list --tag Restart=shui --query "[?type=='Microsoft.Compute/virtualMachines'].id"|jq -r ".[]") --query 'powerState'
On Mac, maybe you could use the following command.
az vm show -d --ids $(az resource list --tag Restart=${TAG_RESTART} --query "[?type=='Microsoft.Compute/virtualMachines'].id" -o table) --query 'powerState'
You could get help by using az vm show -h
--show-details -d : Show public ip address, FQDN, and power states. command will run slow.