azurevirtual-machineazure-powershellrmvhd

Add-AzureRmVhd : Resource group 'ResourceGroupName' could not be found


I'm trying to import VHD via PowerShell in a Virtual Machine but am getting errors.

Add-AzureRmVhd : Resource group 'ResourceGroupName' could not be found.
At line:1 char:1
+ Add-AzureRmVhd  -ResourceGroupName ResourceGroupName -destination 
"https ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : CloseError: (:) [Add-AzureRmVhd], CloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.StorageServices.AddAzureVhdCommand

These are the steps I am following:

  1. Install-Module AzureRM -AllowClobber
  2. Connect-AzureRmAccount
  3. Add-AzureRmVhd -ResourceGroupName VMWinServerFtH -destination "https://vhdexternal.blob.core.windows.net/oldvhd/test.vhd" -LocalFilePath "C:\Users\administrador\Desktop\disk.vhd"

enter image description here

I've already verified the correct spelling of the resource group name.


Solution

  • Note that: AzureRM PowerShell modules will be depreacted on 29 February 2024. Refer this MsDoc.

    I have download VHD file from disk. To import VHD via PowerShell in a Virtual Machine check the below workaround.

    Install-Module -Name az.compute -RequiredVersion 5.2.0
    Get-Module
    

    enter image description here

    Now to import VHD file from local file to storage account you can make use of below commands:

    The Add-AzVhd command uploads an on-premises virtual hard disk to a managed disk or a blob storage account.

    Add-AzVhd -ResourceGroupName -<YourRGName> -Destination "http://contosoaccount.blob.core.windows.net/vhdstore/win7baseimage.vhd" -LocalFilePath "C:\vhd\WinImage.vhd"
    
    

    enter image description here

    To confirm in portal:

    enter image description here