Skip to content

Instantly share code, notes, and snippets.

@steubens
steubens / retrieve-windows-key.ps
Last active February 14, 2017 18:31
Retrieve Windows Key via Powershell
function Get-WindowsKey {
## function to retrieve the Windows Product Key from any PC
param ($targets = ".")
$hklm = 2147483650
$regPath = "Software\Microsoft\Windows NT\CurrentVersion\DefaultProductKey"
$regValue = "DigitalProductId"
Foreach ($target in $targets) {
$productKey = $null
$win32os = $null
$wmi = [WMIClass]"\\$target\root\default:stdRegProv"