Reading Time: 2 minutes

With Azure Stack HCI you can enable Azure Public exclusive services and workloads to be deployed locally in your environment. Services such as:

Other than that, did you know that is possible to use public Azure Marketplace Images to deploy VMs locally? Yes, you got that right! This is also a requirement in the case of AVD local deployment with Windows 10/11 multi-session desktops. In addition, you can enable and make use of Azure Benefits or Windows Server guest licensing offer with the guest VMs running locally on Azure Stack HCI!

Imagine that you are now able to deploy VMs from public Marketplace Images, purchase guest licenses from an Azure subscription, and make use of Azure exclusive features using Azure Benefits!


  1. Access to an Azure Subscription.
  2. Preferably a system (and not the HCI) running PowerShell or PowerShell Core, having the following tools installed:

Assuming that all the above are met, proceed with the following steps below.

Get started

Login to Azure and set the context to a subscription to which you do have access. Replace x values with the corresponding Tenant and Subscription Ids.

Login-AzAccount -TenantId xxx-xxx-xxxxxx-xxxxx

Set-AzContext -SubscriptionId xxxxxx-xxxx-xxxx-xxxxx-xxxxx

A resource group is required to temporarily deploy managed disks using Marketplace Images. If there isn’t any, the following one-liner will create a new resource group under the name “MarketPlaceIMGS-rg".

New-AzResourceGroup -Name "MarketPlaceIMGS-rg" -Location "westeurope"

In our example, the following one-liner would retrieve a list of all the available Windows Server Marketplace Images that are provided by Microsoft. Feel free to explore or download other images.

Get-AzVMImageSku -Location westeurope -PublisherName  "microsoftwindowsserver" -Offer "WindowsServer"

Choose the desired OS version and preferable a small disk(32GB) image to save yourself bandwidth, time, and storage 🙂

$img=Get-AzVMImage -Location "westeurope" -PublisherName  "microsoftwindowsserver" -Offer "WindowsServer" -SKU "2022-datacenter-smalldisk-g2" | Sort-Object Version -Descending | Select-Object -First 1

Create a managed disk from the selected image.

$imgId= $
$imageOSDisk = @{Id = $ImgId}
$diskconfig = New-AzDiskConfig -Location "westeurope" -CreateOption "FromImage" -ImageReference $imageOSDisk
New-AzDisk -ResourceGroupName "MarketPlaceIMGS-rg" -DiskName "2022datacentersmalldiskg2" -Disk $diskconfig

Create the disk and generate a Serial Attached SCSI (SAS) access URL.

$output=Grant-AzDiskAccess -ResourceGroupName  "MarketPlaceIMGS-rg"  -DiskName "2022datacentersmalldiskg2" -Access 'Read' -DurationInSecond 3600

Export the VHD from the managed disk locally. Alternatively, the VHD can be downloaded and stored directly to the HCI Cluster by changing the path to e.g “\\name-of-hci-cluster\c$\ClusterStorage\Name-Of-CSV\Folder\2022datacentersmalldiskg2.vhd”.

azcopy.exe copy $sas "C:\2022datacentersmalldiskg2.vhd" --check-md5 NoCheck 

Optionally, you can also convert the download VHD to a dynamic VHDx.

Convert-VHD -Path "E:\2022datacentersmalldiskg2.vhd" -DestinationPath "E:\2022datacentersmalldiskg2.vhdx" -VHDType Dynamic -DeleteSource

Optimize-VHD -Path "E:\2022datacentersmalldiskg2.vhdx" -Mode Full

Finally, revoke access and clean up the managed disk.

Revoke-AzDiskAccess -ResourceGroupName "MarketPlaceIMGS-rg"  -Name "2022datacentersmalldiskg2"

Remove-AzDisk -ResourceGroupName "MarketPlaceIMGS-rg" -Name "2022datacentersmalldiskg2" -Force

Now that the disk image is stored locally, you can choose either to create differencing disks or to clone it into new disks in order to be used with new Virtual Machines. Note that, all Marketplace images are either Generalized or Specialized.

Thanks for reading my blog!

Feel free to drop your comment or question below.