azureazure-virtual-machineazure-vm-scale-setazure-managed-diskazure-china

Copy Azure Managed Image from Azure Comercial to Azure China


We have a custom Managed Image that we built from Windows VM in Azure. We need to copy that Managed Image to China and create VMs from it. Unfortunately, we are unable to connect to VMs created from copied .vhd. The steps we did: 1. Created VM in Europe from custom Managed Image. 2. Ran Sysprep. 3. Exported Managed Disk, and uploaded .vhd to Storage Account in China. 4. Created VM from that image. The problem is we are not able to RDP to that VM. What is the proper way to do it? (connection time out) We can't recreate that Image in China, because we need that Image to be consistent with the image we have in Europe. enter image description here


Solution

  • A generalized VHD has had all of your personal account information removed using Sysprep. If you intend to use the VHD as an image to create new VMs. You should create a new user name and password to use as the local administrator account.

    The following PowerShell script shows how to set up the virtual machine configurations and use the uploaded VM image as the source for the new installation.

        # Enter a new user name and password to use as the local administrator account 
        # for remotely accessing the VM.
        $cred = Get-Credential
    
        # Name of the storage account where the VHD is located. This example sets the 
        # storage account name as "myStorageAccount"
        $storageAccName = "myStorageAccount"
    
        # Name of the virtual machine. This example sets the VM name as "myVM".
        $vmName = "myVM"
    
        # Size of the virtual machine. This example creates "Standard_D2_v2" sized VM. 
        # See the VM sizes documentation for more information: 
        # https://azure.microsoft.com/documentation/articles/virtual-machines-windows-sizes/
        $vmSize = "Standard_D2_v2"
    
        # Computer name for the VM. This examples sets the computer name as "myComputer".
        $computerName = "myComputer"
    
        # Name of the disk that holds the OS. This example sets the 
        # OS disk name as "myOsDisk"
        $osDiskName = "myOsDisk"
    
        # Assign a SKU name. This example sets the SKU name as "Standard_LRS"
        # Valid values for -SkuName are: Standard_LRS - locally redundant storage, Standard_ZRS - zone redundant
        # storage, Standard_GRS - geo redundant storage, Standard_RAGRS - read access geo redundant storage,
        # Premium_LRS - premium locally redundant storage. 
        $skuName = "Standard_LRS"
    
        # Get the storage account where the uploaded image is stored
        $storageAcc = Get-AzureRmStorageAccount -ResourceGroupName $rgName -AccountName $storageAccName
    
        # Set the VM name and size
        $vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize
    
        #Set the Windows operating system configuration and add the NIC
        $vm = Set-AzureRmVMOperatingSystem -VM $vmConfig -Windows -ComputerName $computerName `
            -Credential $cred -ProvisionVMAgent -EnableAutoUpdate
        $vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id
    
        # Create the OS disk URI
        $osDiskUri = '{0}vhds/{1}-{2}.vhd' `
            -f $storageAcc.PrimaryEndpoints.Blob.ToString(), $vmName.ToLower(), $osDiskName
    
        # Configure the OS disk to be created from the existing VHD image (-CreateOption fromImage).
        $vm = Set-AzureRmVMOSDisk -VM $vm -Name $osDiskName -VhdUri $osDiskUri `
            -CreateOption fromImage -SourceImageUri $imageURI -Windows
    
        # Create the new VM
        New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vm
    

    Ref: Upload a generalized VHD to Azure to create a new VM