Start / If you dont want to create the image using AIB

Create custom WVD image using preprep-ed image from Micha

Prepare your environment

  • Connect to Azure using Powershell
Get-AzSubscription | Out-GridView -PassThru | Select-AzSubscription
  • Set up the base variables & create a new Resource Group
$currentAzContext = Get-AzContext
# destination image resource group
$imageResourceGroup = "myimagebuilder-rg"
$location = "westeurope"
$subscriptionID = $currentAzContext.Subscription.Id
$imageName = "Win1020h2"
$vhdSourceLocation = ""
# create resource group for image and image template resource
if ($null -eq (Get-AzResourceGroup -Name $imageResourceGroup -ErrorAction SilentlyContinue)) {
    New-AzResourceGroup -Name $imageResourceGroup -Location $location
  • Create a new Storage Account & Blob Container to copy the VHD
$saName = ("wvdwshop{0}" -f [guid]::NewGuid().Guid.replace("-","").Substring(0,14))
$sa = New-AzStorageAccount -ResourceGroupName $imageResourceGroup -Name $saName -Location $location -SkuName Standard_LRS -Kind StorageV2
$ctx = $sa.Context
$containerName = "vhds"
$container = New-AzStoragecontainer -Name $containerName -Context $ctx
$sasToken = New-AzStorageContainerSASToken -Name $containerName -Context $ctx -Permission rwdl -ExpiryTime ([dateTime]::Now.AddHours(4))
$vhdTargetLocation = ("{0}/window1020h2Template01.vhd{1}" -f $container.CloudBlobContainer.Uri.AbsoluteUri, $sasToken)
$vhdLocation = ("{0}/window1020h2Template01.vhd" -f $container.CloudBlobContainer.Uri.AbsoluteUri)
  • Download AzCopy
    Now we have to copy the Preprep-ed image to the new Storage Account.
    To do so, we need AzCopy
$azUrl = ""
$targetZip = ("{0}\" -f $env:temp)
$targetFolder = ("{0}\azcopy_windows_amd64" -f $env:temp)
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($azUrl, $targetZip)
Expand-Archive -Path $targetZip -DestinationPath $targetFolder -Force
$azCopyLocation = Get-ChildItem -Path $targetFolder -Recurse | Where-Object {$_.Name -eq "azcopy.exe"}
  • Copy the VHD
    Now we will copy the VHD to the new Storage Account
Start-Process -FilePath $azCopyLocation.FullName -ArgumentList @("cp", $vhdSourceLocation , $vhdTargetLocation) -Wait -Passthru

Create Managed Image from VHD location

  • We have the VHD in a Storage Account, last step is to convert the VHD into a Managed Image so we can use it in the deployment
$imageConfig = New-AzImageConfig -Location $location
$imageConfig = Set-AzImageOsDisk -Image $imageConfig -OsType Windows -OsState Generalized -BlobUri $vhdLocation
$image = New-AzImage -ImageName $imageName -ResourceGroupName $imageResourceGroup -Image $imageConfig