0% found this document useful (0 votes)
101 views

Upload A Generalized VHD and Use It To Create New VMs in Azure

This document provides instructions for uploading a generalized virtual hard disk (VHD) to Azure and using it to create new virtual machines (VMs). It describes how to: 1. Generalize the source VM using Sysprep to remove personal account information and prepare it as an image. 2. Upload the VHD to Azure storage as a managed disk. 3. Create an image from the generalized OS managed disk. 4. Create new VMs from the image using Azure PowerShell, simplifying management with managed disks.

Uploaded by

mateigeorgescu80
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
101 views

Upload A Generalized VHD and Use It To Create New VMs in Azure

This document provides instructions for uploading a generalized virtual hard disk (VHD) to Azure and using it to create new virtual machines (VMs). It describes how to: 1. Generalize the source VM using Sysprep to remove personal account information and prepare it as an image. 2. Upload the VHD to Azure storage as a managed disk. 3. Create an image from the generalized OS managed disk. 4. Create new VMs from the image using Azure PowerShell, simplifying management with managed disks.

Uploaded by

mateigeorgescu80
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

https://docs.microsoft.

com/en-us/azure/virtual-machines/windows/upload-generalized-managed

Upload a generalized VHD and use it to


create new VMs in Azure
This article walks you through using PowerShell to upload a VHD of a generalized VM to Azure, create an image from the VHD, and
create a new VM from that image. You can upload a VHD exported from an on-premises virtualization tool or from another cloud.
Using Managed Disks for the new VM simplifies the VM management and provides better availability when the VM is placed in an
availability set.

For a sample script, see Sample script to upload a VHD to Azure and create a new VM.

Before you begin


 Before uploading any VHD to Azure, you should follow Prepare a Windows VHD or VHDX to upload to Azure.
 Review Plan for the migration to Managed Disks before starting your migration to Managed Disks.

Generalize the source VM by using Sysprep


If you haven't already, you need to Sysprep the VM before uploading the VHD to Azure. Sysprep removes all your personal account
information, among other things, and prepares the machine to be used as an image. For details about Sysprep, see the Sysprep
Overview.

Make sure the server roles running on the machine are supported by Sysprep. For more information, see Sysprep Support for Server
Roles.

Important

If you plan to run Sysprep before uploading your VHD to Azure for the first time, make sure you have prepared your VM.

1. Sign in to the Windows virtual machine.


2. Open the Command Prompt window as an administrator. Change the directory to %windir%\system32\sysprep, and then
run sysprep.exe.
3. In the System Preparation Tool dialog box, select Enter System Out-of-Box Experience (OOBE), and make sure that
the Generalize check box is enabled.
4. For Shutdown Options, select Shutdown.
5. Select OK.
6. When Sysprep finishes, it shuts down the virtual machine. Do not restart the VM.

Upload the VHD


You can now upload a VHD straight into a managed disk. For instructions, see Upload a VHD to Azure using Azure PowerShell.

Once the VHD is uploaded to the managed disk, you need to use Get-AzDisk to get the managed disk.

Azure PowerShellCopy
Try It
$disk = Get-AzDisk -ResourceGroupName 'myResourceGroup' -DiskName 'myDiskName'

Create the image


Create a managed image from your generalized OS managed disk. Replace the following values with your own information.

First, set some variables:

PowerShellCopy
$location = 'East US'
$imageName = 'myImage'
$rgName = 'myResourceGroup'

Create the image using your managed disk.

Azure PowerShellCopy
Try It
$imageConfig = New-AzImageConfig `
-Location $location
$imageConfig = Set-AzImageOsDisk `
-Image $imageConfig `
-OsState Generalized `
-OsType Windows `
-ManagedDiskId $disk.Id

Create the image.

Azure PowerShellCopy
Try It
$image = New-AzImage `
-ImageName $imageName `
-ResourceGroupName $rgName `
-Image $imageConfig

Create the VM
Now that you have an image, you can create one or more new VMs from the image. This example creates a VM
named myVM from myImage, in myResourceGroup.

PowerShellCopy
New-AzVm `
-ResourceGroupName $rgName `
-Name "myVM" `
-Image $image.Id `
-Location $location `
-VirtualNetworkName "myVnet" `
-SubnetName "mySubnet" `
-SecurityGroupName "myNSG" `
-PublicIpAddressName "myPIP" `
-OpenPorts 3389

Next steps
Sign in to your new virtual machine. For more information, see How to connect and log on to an Azure virtual machine running
Windows.

You might also like