Upload A Generalized VHD and Use It To Create New VMs in Azure
Upload A Generalized VHD and Use It To Create New VMs in Azure
com/en-us/azure/virtual-machines/windows/upload-generalized-managed
For a sample script, see Sample script to upload a VHD to Azure and create a new VM.
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.
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'
PowerShellCopy
$location = 'East US'
$imageName = 'myImage'
$rgName = 'myResourceGroup'
Azure PowerShellCopy
Try It
$imageConfig = New-AzImageConfig `
-Location $location
$imageConfig = Set-AzImageOsDisk `
-Image $imageConfig `
-OsState Generalized `
-OsType Windows `
-ManagedDiskId $disk.Id
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.