OpsaC - Operating as PowerShell code
published: January 28, 2019 author: Tinu tags: PowerShell categories: System-Engineering
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.
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.
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’.
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’.
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()
}
}
How to troubleshoot the Key Management Service (KMS)
IDERA Managing Windows License Key