Skip to content

MDT2013 Automated Activation

As an MSP we use the product keys stored in the BIOS to activate the systems installed via MDT 2013.
Doing this per computer does take a while if you put out a few hundred machines a year; retrieving the key, copy, entering, activating.

With the help of someone else already creating a nice function to check the activation status;

https://social.technet.microsoft.com/wiki/contents/articles/5675.determine-windows-activation-status-with-powershell.aspx

I have created a simple activation script via Powershell to be launched as a task in an MDT task sequence.

function Get-ActivationStatus {
[CmdletBinding()]
    param(
        [Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [string]$DNSHostName = $Env:COMPUTERNAME
    )
    process {
        try {
            $wpa = Get-WmiObject SoftwareLicensingProduct -ComputerName $DNSHostName `
            -Filter "ApplicationID = '55c92734-d682-4d71-983e-d6ec3f16059f'" `
            -Property LicenseStatus -ErrorAction Stop
        } catch {
            $status = New-Object ComponentModel.Win32Exception ($_.Exception.ErrorCode)
            $wpa = $null    
        }
        $out = New-Object psobject -Property @{
            ComputerName = $DNSHostName;
            Status = [string]::Empty;
        }
        if ($wpa) {
            :outer foreach($item in $wpa) {
                switch ($item.LicenseStatus) {
                    0 {$out.Status = "Unlicensed"}
                    1 {$out.Status = "Licensed"; break outer}
                    2 {$out.Status = "Out-Of-Box Grace Period"; break outer}
                    3 {$out.Status = "Out-Of-Tolerance Grace Period"; break outer}
                    4 {$out.Status = "Non-Genuine Grace Period"; break outer}
                    5 {$out.Status = "Notification"; break outer}
                    6 {$out.Status = "Extended Grace"; break outer}
                    default {$out.Status = "Unknown value"}
                }
            }
        } else {$out.Status = $status.Message}
        $out
    }
}



$Key = powershell “(Get-WmiObject -query ‘select * from SoftwareLicensingService’).OA3xOriginalProductKey”
$Activate = Get-ActivationStatus

Start-Process cscript.exe "C:\Windows\System32\slmgr.vbs /ipk $($Key.ToString())"
Write-Host Product key is being added... -BackgroundColor Green

Start-Sleep 5

Start-Process cscript.exe "C:\Windows\System32\slmgr.vbs /ato"
Write-Host Windows is being activated... -BackgroundColor Green

Start-Sleep 15

if ($Activate.Status -eq 'Licensed'){

Write-Host $Activate.ComputerName license status is $Activate.Status -BackgroundColor Green

}

else {

Write-Host $Activate.ComputerName license status is $Activate.Status -BackgroundColor Red
$Key | Out-File "$env:USERPROFILE\Desktop\License.txt"
}

Write-Host License.txt is added to the Desktop incase activation did not succeed. -BackgroundColor Green

Save the PowerShell script in the scriproot, located under the \\DeploymentShare$\Scripts

Next we create a new “Run PowerShell Script” task;


Don’t forget to update the DeploymentShare and happy activating!

Published inMDT2013PowerShellWindows Server

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *