Activate all running VMs on Hyper-V host using Powershell

Objective:

Activate all running Virtual Machines with Windows server 2012 R2 OS installed from SPLA ISO image using MAK key. I am not going to use AVMA – Automatic VM Activation as my Hyper-V OS is not Datacenter. I am using either Hyper-V Server or WS 2012 R2 Standard.

Check Activation Status on single VM:

$VM = „yourVMname“

$cim = new-cimsession -ComputerName $VM

get-ciminstance -class softwarelicensingproduct -cimsession $cim |where {$_.name -match ‚windows‘ -and $_.licensefamily} | format-table -Property PScomputername,Name,Description,Licensestatus

notActivatedVM

Activate Single VM with MAK license key:

new-item -path „c:\temp\activate.cmd“ -type file

#add your MAK key

add-content „c:\temp\activate.cmd“ „cscript //B %windir%/system32/slmgr.vbs /ipk xxxxx-xxxxx-xxxxx-xxxxx-xxxxx“

$FilePath = „c:\temp\activate.cmd“

#add your VM name

$VMName = „yourVMname“

$VMName |Enable-VMIntegrationService -name „Guest Service Interface“

copy-vmfile $VMName -sourcepath  $FilePath -DestinationPath C: -filesource Host

invoke-command -ComputerName $VMName -ScriptBlock {

Start-Process C:\activate.cmd -verb runas -wait

remove-item C:\activate.cmd -ErrorAction SilentlyContinue}

$VMName |Disable-VMIntegrationService -name „Guest Service Interface“

 activatedVM

Check Activation Status on all VMs running on Hyper-V host:

$cim = new-cimsession -ComputerName (get-VM).name

get-ciminstance -class softwarelicensingproduct -cimsession $cim |where {$_.name -match ‚windows‘ -and $_.licensefamily} | ft -Property PScomputername,Name,Description

 

Activate all running VMs on Hyper-V host with MAK license key:

new-item -path „c:\temp\activate.cmd“ -type file

add-content „c:\temp\activate.cmd“ „cscript //B %windir%/system32/slmgr.vbs /ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX“

$FilePath = „c:\temp\activate.cmd“

#add your HV host name

$VMNames = get-vm  –ComputerName HyperVHOST  | Where-Object {$_.State –eq ‚Running‘}

$VMNames  |Enable-VMIntegrationService -name „Guest Service Interface“

foreach ($VMName in $VMNames)

{

$server = $VMName.Name

write-host „Working on“ $server -foregroundcolor red -backgroundcolor yellow

copy-vmfile $VMName -sourcepath  $FilePath -DestinationPath C: -filesource Host

invoke-command -ComputerName $Server -ScriptBlock {

Start-Process C:\activate.cmd -verb runas -wait

remove-item C:\activate.cmd -ErrorAction SilentlyContinue}

}

$VMName |Disable-VMIntegrationService -name „Guest Service Interface“

remove-item C:\activate.cmd -ErrorAction SilentlyContinue

Now we can check how many VMs have licensestatus „1“ which means „Activated“

$cim = new-cimsession -ComputerName (get-VM).name

get-ciminstance -class softwarelicensingproduct -cimsession $cim |where {$_.name -match ‚Windows‘ -and $_.Licensestatus -eq ‚1‘} | ft -Property PScomputername,Name,Description, Licensestatus

 activatedVMs

Pridaj komentár

Vaša e-mailová adresa nebude zverejnená. Vyžadované polia sú označené *