Azure IaaS: Build a VM from a Bring your Own License (BYOL) image with Azure PowerShell
9:16 am in ARM, Azure, Azure Hybrid Use Benefit, BYOL, Cloud, IaaS, PowerShell by Wim Matthyssen
For all people who do not yet know, with the Azure Hybrid Use Benefit you can use your on-premises Windows Server licenses that includes Software Assurance for Windows Server (Standard and Datacenter Editions) virtual machines (VM) in Azure. More recently also Azure Hybrid Use Benefits for Windows Client which includes Windows 10 (only Enterprise customers with Windows 10 Enterprise E3/E5 per user or Windows VDA per user – User Subscription Licenses or Add-on User Subscription Licenses – are eligible) came in Preview.
By using your existing licenses, you only pay for the base compute rate (equal to the Linux rate for VMs) without the Windows licenses cost, which can save you up to 40 %.
You can download the Azure Hybrid Use Benefit datasheet here
These days it’s even simpler to deploy a new Azure server VM whit your own on premise license via the Windows Server BYOL images available in the Azure Marketplace. There are images available for the following Server Oss (*be aware that not all Azure Subscriptions can use the BYOL images):
- Windows Server 2008 R2 SP1
- Windows Server 2012
- Windows Server 2012 R2
- Windows Server 2016 (not available in all regions)
You can search for the Windows Server images by running following PowerShell command:
1 2 3 4 5 6 7 |
## Log on with your Azure account Login-AzureRmAccount ## Check which Windows Server BYOL images are available in your region Get-AzureRmVMImagesku -Location 'westeurope' -PublisherName 'MicrosoftWindowsServer' -Offer 'WindowsServer' |format-table Skus |
In the above screenshot, you can see that some Skus now contain the BYOL suffix.
You can search for the Windows Client images by running following PowerShell command:
1 2 3 |
## Check which Windows Client BYOL images are available in your region Get-AzureRMVMImageSku -Location 'westeurope' -Publisher 'MicrosoftWindowsServer' -Offer 'Windows-HUB'|format-table Skus |
To build a VM with from a BYOL image you can run following Azure PowerShell script (adjust all variables for your own use):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
## Built a VM with from a Windows Server BYOL image # Variables $RGCompute = "RG_Compute" $RGNetworking = "RG_Network" $RGStorage = "RG_Storage" $StorAccNameOS = "vlabos001" $VMName = "VM1-BYOL" $Location = "westeurope" $VNetName = "AZU-Vnet-ARM" $SubnetName = "Front-End" $IPAddressVM = "10.0.2.20" $osSKU = "2012-R2-Datacenter-BYOL" $VMSize = "Standard_A2_v2" ## ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # Create the Public IP Address (PIP) $PIP = New-AzureRmPublicIpAddress -Name "${VMName}-pip" -ResourceGroupName $RGCompute -Location $Location -AllocationMethod Static ## ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # Create the NIC # Get the VNET to which to connect the NIC $VNet = Get-AzureRmVirtualNetwork -Name $VNetName -ResourceGroupName $RGNetworking # Get the Subnet ID to which to connect the NIC $SubnetID = (Get-AzureRmVirtualNetworkSubnetConfig -Name $SubnetName -VirtualNetwork $VNET).Id $NIC = New-AzureRmNetworkInterface -Name "${VMName}-nic1" -ResourceGroupName $RGCompute -Location $Location -SubnetId $SubnetID -PrivateIpAddress $IPAddressVM -PublicIpAddressId $PIP.Id ## ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # Specify local administrator account $Username = "local_tmpadmin" $Password = "BYOL23,ArM:2411;" $Passwordsec = convertto-securestring $Password -asplaintext -force $Creds = New-Object System.Management.Automation.PSCredential($Username, $Passwordsec) ## $cred = Get-Credential -Message "Type the name and password of the local administrator account." ## ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- # Specify the image $Images = Get-AzureRmVMImage -Location $Location -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer" -Skus $osSKU | Sort-Object -Descending -Property PublishedDate ## ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- v $VM = New-AzureRmVMConfig -Name $VMName -VMSize $VMSize $VM = Add-AzureRmVMNetworkInterface -VM $VM -Id $NIC.Id #Specify the OS Disk $StorAcct1 = Get-AzureRmStorageAccount -ResourceGroupName $RGStorage –StorageAccountName $StorAccNameOS $OSDiskName = $VMName + "-c" $OSDiskUri = $StorAcct1.PrimaryEndpoints.Blob.ToString() + "vhds/" + $OSDiskName + ".vhd" Set-AzureRmVMOperatingSystem -Windows -VM $VM -ProvisionVMAgent -EnableAutoUpdate -Credential $creds -ComputerName $VMName Set-AzureRmVMSourceImage -VM $VM -PublisherName $Images[0].PublisherName -Offer $Images[0].Offer -Skus $Images[0].Skus -Version $Images[0].Version Set-AzureRmVMOSDisk -VM $VM -Name $OSDiskName -VhdUri $OSDiskUri -Caching ReadWrite -CreateOption fromImage New-AzureRmVM -ResourceGroupName $RGCompute -Location $location -VM $VM -Verbose ## ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
The script is also available on Microsoft TechNet
When the script is completed and the VM is build, you can log into the VM via remote desktop. Like you can see the VM is not registered and you’ll able to use your own Windows product key.
Hope this comes in handy!
Wim Matthyssen (@wmatthyssen)
Recent Comments