Hello folks,
Automatic Virtual Machine Activation! is a 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.
Table of Contents
Requirements
To take advantage of this feature, AVMA requires that the host run Windows Server 2012 R2 Datacenter and that the guest virtual machine OS be either Windows Server 2012 R2 Datacenter, Windows Server 2012 R2 Standard, or Windows Server 2012 R2 Essentials.
// See also: Automatic VM Activation for Windows Server in Windows Admin Center.
How To Automatic Activate Windows Server
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 is to activate Windows Server 2012 R2 VM.
Scenario
You have deployed several virtual machines from a template without SCVMM or a deployment tool such as MDT, where you can inject the 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.
// See also: Automate The Activation Of Windows Server 2019 Virtual Machines with PowerShell.
Automatic Activate Windows Server VMs
Here we go:
First, we need to check 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 have not been activated yet!
So let’s activate them automatically using PowerShell combined with the 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 the license status of all virtual machines is.
# 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 much easier than having to activate each VM manually.
Make sure to check my recent Windows Server Hyper-V Cookbook for in-depth details about Hyper-V!
Enjoy your day!
__
Thank you for reading our blog.
Please let us know in the comments section below if you have any questions or feedback.
-Charbel Nemnom-