I'm looking for powershell command to get an Azure Windows VM plan info. I looked up Get-AzVM, but unable to find the required info.
Here's the property on azure portal, that I'm looking for
Please find the below screenshot to get the vm plan information
CLI
az vm show --name myvm --resource-group test --query storageProfile.imageReference.sku
Powershell
Get-AzVM -ResourceGroupName test -Name myvm -Status | select OsName
To get the status of all vms in the resource group :
Get-AzVM -ResourceGroupName test -Status
If this solve your problem then mark this your answer 👍
Use the below query:
az vm show --name myvm --resource-group test --query storageProfile.imageReference.sku
Related
I am newbie with microsoft azure and trying to study and follow the tutorial.
But my problem is, here is my tutorial :
# generate a unique name and store as a shell variable
webappname=mywebapp$RANDOM
# create a resource group
az group create --location westeurope --name myResourceGroup
# create an App Service plan
az appservice plan create --name $webappname --resource-group myResourceGroup --sku FREE
# create a Web App
az webapp create --name $webappname `
--resource-group myResourceGroup `
--plan $webappname
And my problem is, when I coded the code az group create --location westeurope --name myResourceGroup, it always said to me that I must login to azure but I login to azure before that.
And when I searched how to create a web app with azure CLI online, it show me a very different version command like this
https://www.youtube.com/watch?v=qILUM6DyruM
Could you please give me some advise for this problem ? Thank you in advance.
I am geeting the error while I try to attach the Azure Container Registry to the AKS using Visual studio
syntax:
az aks update --name $CLUSTER_NAME --resource-group $RESOURCE_GROUP --attach-acr $ACR_NAME
Error:
microsoft.containerregistry/registries' could not be found in subscription
I have logged into the correct subscription and also set the correct subscription
az login --tenant $TENANT_ID
az account set --subscription $SUBSCRIPTION
az acr list also shows me the acr that is created
any possible solution for this?
Tested in my environment it is working fine for me, The error you are getting is due to you are looking into wrong subscription. When you use the CLI command az login then you log in with a default subscription. For you, it seems the "Some Other susbscription" is the default. You should check if your registry is in the current subscription. If not, you should set that subscription as the current subscription through the CLI command:
az account set --subscription subscription_id
Now would suggest you to check if the registry exists in current subscription with the CLI command:
az acr show -n acr_name
Also, you can set the subscription in the login time with the parameter --subscription through the CLI command az login.
Reference : az acr - Unable to find repository in case of multiple subscription on single account
I am trying to find a way to delete an Instance in azure and all its associated resources. But I don't see any straightforward approach to accomplish it. I am using az vm delete -g resourcegroup -n myinstancename--yes command which currently only deletes instances. In my scenario, I can't use powershell.
For testing ,I created a VM with 1 NIC, 1 Public IP and 2 Data disks.
Then, I used the below az CLI script :
$osDisk = (az vm show --resource-group ansumantest --name ansumantest --query "storageProfile.osDisk.name" --output tsv)
$datadisks = (az vm show --resource-group ansumantest --name ansumantest --query "storageProfile.dataDisks[].name" --output tsv)
$nics= (az vm show --resource-group ansumantest --name ansumantest --query "networkProfile.networkInterfaces[].id" --output tsv)
foreach ($nic in $nics){
$publicIps=az network nic show --id $nic --query "ipConfigurations[].publicIpAddress.id" --output tsv
}
az vm delete --resource-group ansumantest --name ansumantest --yes
if ($osDisk) {
az disk show --resource-group ansumantest --name $osDisk --yes
}
foreach ($datadisk in $Datadisks){
az disk delete --resource-group ansumantest --name $datadisk --yes
}
foreach ($nic in $nics){
az network nic delete --id $nic
}
foreach ($publicIp in $publicIps){
az network public-ip delete --id $publicIp
}
Outputs:
OR
You can directly delete all the resources while the running the VM delete Command as well but there are some Prerequisites for this method i.e. While creating the VM using CLI you have to configure couple of features like below :
As per Microsoft Document in az vm create section:
[--os-disk-delete-option {Delete, Detach}]
Specify the behavior of
the managed disk when the VM gets deleted i.e whether the managed
disk is deleted or detached.
accepted values: Delete, Detach
[--data-disk-delete-option]
Specify whether data disk should be deleted or detached upon VM deletion.
[--nic-delete-option]
Specify what happens to the network interface when the VM is
deleted. Use a singular value to apply on all resources, or use = to
configure the delete behavior for individual resources. Possible
options are Delete and Detach.
If the above 3 are configured to delete while creating the VM then , when you run the az vm delete it defaults to delete these resources when the VM is to be deleted.
Reference:
Github Support
I have a resource group with all of my networking in it. I need to create a VM in another resource group but using the vnets/subnet in the other resource group. It is failing miserably at the cli. Here's the command I'm using:
az vm create --name vm-jmp-poc-e --resource-group rg-mgmt-poc-eastus-001 --public-ip-address "" --image Win2016Datacenter --data-disk-sizes-gb 10 --admin-user adminuser --admin-password ThisIsThePass123$ --availability-set av-cpe-poc-eastus-001 --subnet subscriptions/938b61f6-ecac-4c61-ad3b-7e856c377660/resourceGroups/providers/Micosoft.Network/virtualNetworks/rg-sql-cpe-poc-eastus-001/vnet-primary-poc-eastus-001/subnets/snet-mgmt-poc-eastus-002 --location eastus
Here is the error:
ValidationError: incorrect usage: --subnet ID | --subnet NAME
--vnet-name NAME
Please help!!!
The problem is that you have provided a wrong subnet ID, the correct format is that
/subscriptions/<subscriptionID>/resourceGroups/<rgName>/providers/Microsoft.Network/virtualNetworks/<vnetName>/subnets/<subnetName>
You can get the subnet ID via
az network vnet subnet show -g <rgName> -n <subnetName> --vnet-name <vnetName> --query id -o tsv
You lack the resource group name in your providing subnet ID.
subscriptions/xxxx/resourceGroups/providers/Micosoft.Network/virtualNetworks/rg-sql-cpe-poc-eastus-001/vnet-primary-poc-eastus-001/subnets/snet-mgmt-poc-eastus-002
Result
I tried to create 2 virtual machines with the same parameters but with 2 different ways:
The Powershell cmdlet:
New-AzVm -ResourceGroupName $rg -Name "Testing1img" -Credential $credential -Image UbuntuLTS
Azure CLI from Powershell:
az vm create `
--name "Testing2img" `
--resource-group $rg `
--admin-username $credential.UserName `
--admin-password $credential.Password `
--image "UbuntuLTS"
Both create an Ubuntu LTS VM on the same resource group (different name). The problem I have is that they create VMs with slightly different settings.
In the first case it creates:
an Ubuntu 16.04 Linux
DNS name is being assigned
In the second case we have:
an Ubuntu 18.04 Linux
No Dns name is being configured
Why these (even small) differences? Shouldn't they both create the same exact VMs? Someone asking for an UbuntuLTS would expect the latest available image and not 16.04.
For New-AzVM you can specify the Ubuntu version with...
-Image Canonical:UbuntuServer:18.04-LTS:latest
My experience shows that functionalities are often delivered in different time frames for individual tools. I often came across commands that used methods other than those recommended in the documentation.
I'm not sure how this looks like for the PowerShell module but the azure CLI code is available on GitHub. So it's possible to verify which endpoints are used and i think the same is possible for debug mode in PowerShell.
https://github.com/Azure/azure-cli/blob/e4a2e19855b2ff0964d084239de9f3f230e67be4/src/azure-cli/azure/cli/command_modules/vm/custom.py#L682