Hello folks,
Automatic Virtual Machine Activation! is pretty cool feature…
Automatic Virtual Machine Activation (AVMA) is a feature that was introduced in Windows Server 2012 R2. AVMA binds the virtual machine activation to the licensed virtualization server and activates the virtual machine when it starts up. This eliminates the need to enter licensing information and activate each virtual machine individually.
Requirements:
In order to get benefits of this feature, AVMA requires that the host is running Windows Server 2012 R2 Datacenter and that the guest virtual machine OS is either Windows Server 2012 R2 Datacenter, Windows Server 2012 R2 Standard or Windows Server 2012 R2 Essentials.
How to:
This is a one step process. Once the Hyper-V host (Windows Server 2012 R2 Datacenter) is activated and guest virtual machines are running smoothly (without activation of course!), the only remaining step is to install the AVMA client key on the guest virtual machines (Data Center, Standard or Essentials). To manually install the key using Command line use the following Syntax from an administrative Command prompt inside the guest OS:
C:\>slmgr.vbs /ipk AVMA Key
Where the generic AVMA Key is selected according to the Guest OS Edition, more information here.
Note:
The whole activation process does not require any network connection of any sort between the Hyper-V host and the guest OS.
This is how the manual approach to activate Windows Server 2012 R2 VM.
Scenario:
You have deployed several virtual machines from a template without SCVMM or deployment tool such as MDT where you can inject above process during the deployment, and now you want to activate all VMs.
Of course you could use the manual approach above, but the easiest way is to use PowerShell, I have created a small script that takes care of all the steps for you:
Here we go:
First we need to check what is the License Status of all Virtual Machines? you can run the following cmdlet to get all VMs on a single host:
# Turn On Offline Virtual Machines Get-VM | ?{$_.State -eq "Off"} | Start-VM # Check Virtual Machines License Status: UNLICENSED $cim = New-CimSession -ComputerName (Get-VM).name get-ciminstance -class SoftwareLicensingProduct -CimSession $cim | where {$_.name -match 'windows' -and $_.licensefamily} | format-list -property Name, Description, ` @{Label= "License Status"; Expression={switch (foreach {$_.LicenseStatus}) ` { 0 {"Unlicensed"} ` 1 {"Licensed"} ` 2 {"Out-Of-Box Grace Period"} ` 3 {"Out-Of-Tolerance Grace Period"} ` 4 {"Non-Genuine Grace Period"} ` } } }
We found out that all virtual machines are not activated yet!
So let’s activate them automatically using PowerShell combined with Hyper-V Guest Services feature
# Create AVMA file including Windows Server 2012 R2 Standard Generic Key # NOTE! Choose the proper generic key according to the Guest OS Edition # https://technet.microsoft.com/en-us/library/dn303421.aspx New-Item -Path "C:\AVMA.cmd" -Type file Add-Content C:\AVMA.cmd "cscript //B %windir%/system32/slmgr.vbs /ipk DBGBW-NPF86-BJVTX-K3WKJ-MTB6V" # Define variables $AVMAFilePath = "C:\AVMA.cmd" # Get all VMs on a single Host $VMNames = Get-VM # Enable Hyper-V Guest Services $VMNames | Enable-VMIntegrationService -Name "Guest Service Interface" Foreach ($VMName in $VMNames) { Copy-VMFile $VMName -SourcePath $AVMAFilePath -DestinationPath C: -FileSource Host Invoke-Command -ComputerName $VMName.Name -ScriptBlock { start-process C:\AVMA.cmd -Verb runas -Wait Remove-Item C:\AVMA.cmd -ErrorAction SilentlyContinue} } $VMNames | Disable-VMIntegrationService -Name "Guest Service Interface" Remove-Item C:\AVMA.cmd -ErrorAction SilentlyContinue
Finally, let’s check again what is the License Status of all Virtual Machines.
# Check if the Virtual Machines are activated: LICENSED $cim = New-CimSession -ComputerName (Get-VM).name get-ciminstance -class SoftwareLicensingProduct -CimSession $cim | where {$_.name -match 'windows' -and $_.licensefamily -and $_.description -match 'VIRTUAL_MACHINE_ACTIVATION'} | format-list -property Name, Description, ` @{Label= "License Status"; Expression={switch (foreach {$_.LicenseStatus}) ` { 0 {"Unlicensed"} ` 1 {"Licensed"} ` 2 {"Out-Of-Box Grace Period"} ` 3 {"Out-Of-Tolerance Grace Period"} ` 4 {"Non-Genuine Grace Period"} ` } } }
Sure enough there are different ways to accomplish the same result, but nevertheless it has worked for me and I feel that it’s a much easier than having to activate each VM manually.
Enjoy your day!
Cheers,
-Charbel