$Server = "CORE-KMS\ADK"
$Query = "
SELECT DisplayName,COUNT(*) AS Activations
FROM (
SELECT DISTINCT ComputerName,CMID,ProductId
FROM KMS.dbo.kms_activations
WHERE Timestamp > (SELECT DATEADD(MONTH,-2,CURRENT_TIMESTAMP))
) AS P1
JOIN KMS.dbo.product_id AS P2 ON P2.ProductID=P1.ProductID
GROUP BY DisplayName
ORDER BY DisplayName,Activations DESC"
$Activations = Invoke-Sqlcmd -ServerInstance $Server -Query $Query
$Activations | Format-Table -AutoSize
$Desktop = 0
$Server = 0
$Office = 0
$Activations | Where-Object { $_.DisplayName -like "Microsoft Windows 7*" -or $_.DisplayName -like "Microsoft Windows 8*" } | ForEach-Object { $Desktop += $_.Activations }
$Activations | Where-Object { $_.DisplayName -like "Microsoft Windows Server*" } | ForEach-Object { $Server += $_.Activations }
$Activations | Where-Object { $_.DisplayName -like "Microsoft Office 20*" } | ForEach-Object { $Office += $_.Activations }
Write-Host "Desktop systems activations: $Desktop"
Write-Host "Server systems activations: $Server"
Write-Host "Office activations: $Office"