Tinus EngOps Wiki

Logo

OpsaC - Operating as PowerShell code

Links

Home

PowerShell Blog

PowerShell Index

PowerShell Search

Additional Websites

View my GitHub Profile

View my GitHub Gists

View Tinus IT Wiki

View my Photo Website

Key Management Service

published: January 28, 2019 author: Tinu tags: PowerShell categories: System-Engineering


Table of Contents

Get KMS from Registry

How to obtain the registered KMS server from the registry:

Get-Item 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform'

The KMS Server is list on KeyManagementServiceName.

Get KMS from DNS

nslookup -type=SRV _vlmcs._tcp

Server:  dnsserver.firma.tld
Address:  10.1.1.1.

_vlmcs._tcp.firma.tld   SRV service location:
          priority       = 0
          weight         = 0
          port           = 1688
          svr hostname   = dc1.firma.tld
dc1.firma.tld  internet address = 10.1.2.3

The KMS Server is list on svr hostname.

Get KMS from Software licensing service

How to obtain the registered KMS server from the Software licensing service (slmgr):

cscript "$($env:windir)\system32\slmgr.vbs" -dlv //Nologo

The KMS Server is list on ‘KMS machine IP address’.

Get KMS from CIM Class

How to obtain the registered KMS server from the Software licensing class:

$properties = @('Name', 'Description', 'PartialProductKey', 'ProductKeyChannel', 'trustedTime', 'KeyManagementServiceMachine', 'KeyManagementServicePort')
Get-CimInstance -Class SoftwareLicensingProduct -Filter 'ProductKeyId != NULL' | Where-Object {
    ($_.LicenseStatus -eq 1 -and $_.Name -match 'Windows')
} | Select $properties

Notice that LicenseStatus 1 is licensed, 0 is not licensed.

The KMS Server is list on ‘KeyManagementServiceMachine’.

List KMS Events from Applicationlog

function Get-KMSEvents{
    <#
        Get events in the last 24 hours with id 12288 or id 12289 from Applicationlog
    #>
    $function = $($MyInvocation.MyCommand.Name)
    try{
        write-host "`nGet KMS Eventlogs:"
        [DateTime]$now = Get-Date
        [DateTime]$after = $now.AddHours(-12)
        [DateTime]$before = $now
        $events = Get-EventLog 'Application' -After $after -Before $before | where {$_.eventID -like 12288 -or $_.eventID -like 12289} | Select TimeGenerated,Message
        if($events -ne $null){
            write-host "`nGet Activation Information from Applicationlog:"
            $events | % {"$($_.TimeGenerated) $($_.Message)"}
        }
    }
    catch [Exception]{
          write-host "$($function): $($_.Exception.Message)" -ForegroundColor Red
          $error.clear()
    }
}

See also

How to troubleshoot the Key Management Service (KMS)

IDERA Managing Windows License Key


[ Top ] Copyright © 2024 by tinuwalther [ Blog ] Next Post →