简体   繁体   中英

azure powershell can't find resource (vm) by name

I am trying to increase the size of my azure linux VM disk through powershell as the azure portal dashboard can't do it for this VM. I am having trouble getting the VM in the resource group, it can't be found.

Note the resource group and resource name are the same. Is there an alternative way of getting the resource, I have tried by ID but no luck

Select-AzureRmSubscription –SubscriptionName 'BizSpark'
$rgName = 'abc'
$vmName = 'abc'
$vm = Get-AzureRmVM -ResourceGroupName $rgName -Name $vmName

The error am getting is

Get-AzureRmVM : The Resource 'Microsoft.Compute/virtualMachines/abc' under resource group 'abc' was not found.

According to your description, it seems that your have multiple subscriptions and your VM is not in your default subscription. So, you need select correct subscriptions. Please refer the following steps:

1.Determine your subscription name and subscription id in Azure Portal.

在此处输入图片说明

2.Change the default subscription.

Get-AzureRmSubscription
Select-AzureRmSubscription -SubscriptionName "your subscription name"

Update:

If your VM is based on classic VM, you need use Get-AzureVM to list your VM.

Have you tried without specifying the resource group eg

#Login to your sub
login-azurermaccount
Select-AzureRmSubscription -SubscriptionName 'BizSpark'
$vms = Get-AzureRmVM
#list all the VMs returned by the above command
$vms
#first VM in the above collection
$vms[0]
#id of first vm
$vms[0].id

If that doesn't work, it is worth checking you are running the latest version of the cmdlets as I have encountered some great behaviors that have been fixed by updating. https://docs.microsoft.com/en-us/powershell/azureps-cmdlets-docs/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM