Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, May 7, 2013 12:21 PM
Hi,
Im trying to rung the following script:
http://gallery.technet.microsoft.com/scriptcenter/Get-product-keys-of-local-83b4ce97
But it doesnt display anything, I have tried with attributes also for example
.\Get-ProductKey.ps1 localhost
.\Get-ProductKey.ps1 dc1
I have run powershell with administrator rights, and i have tried it on several servers.... We are running Windows 2008 R2
What am i missing ? or is there another script that is better ?
Thanks for answers
/R
Andreas
All replies (5)
Tuesday, May 7, 2013 12:23 PM âś…Answered
this works nicely
function Get-WindowsKey { ## function to retrieve the Windows Product Key from any PC param ($targets = ".") $hklm = 2147483650 $regPath = "Software\Microsoft\Windows NT\CurrentVersion" $regValue = "DigitalProductId" Foreach ($target in $targets) { $productKey = $null $win32os = $null $wmi = [WMIClass]"\\$target\root\default:stdRegProv" $data = $wmi.GetBinaryValue($hklm,$regPath,$regValue) $binArray = ($data.uValue)[52..66] $charsArray = "B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9" ## decrypt base24 encoded binary data For ($i = 24; $i -ge 0; $i--) { $k = 0 For ($j = 14; $j -ge 0; $j--) { $k = $k * 256 -bxor $binArray[$j] $binArray[$j] = [math]::truncate($k / 24) $k = $k % 24 } $productKey = $charsArray[$k] + $productKey If (($i % 5 -eq 0) -and ($i -ne 0)) { $productKey = "-" + $productKey } } $win32os = Get-WmiObject Win32_OperatingSystem -computer $target $obj = New-Object Object $obj | Add-Member Noteproperty Computer -value $target $obj | Add-Member Noteproperty Caption -value $win32os.Caption $obj | Add-Member Noteproperty CSDVersion -value $win32os.CSDVersion $obj | Add-Member Noteproperty OSArch -value $win32os.OSArchitecture $obj | Add-Member Noteproperty BuildNumber -value $win32os.BuildNumber $obj | Add-Member Noteproperty RegisteredTo -value $win32os.RegisteredUser $obj | Add-Member Noteproperty ProductID -value $win32os.SerialNumber $obj | Add-Member Noteproperty ProductKey -value $productkey $obj }}
http://www.randomtechtips.com/get-windows-product-key-using-powershell/
MK
Tuesday, May 7, 2013 1:22 PM
Hi,
Im trying to rung the following script:
http://gallery.technet.microsoft.com/scriptcenter/Get-product-keys-of-local-83b4ce97
But it doesnt display anything, I have tried with attributes also for example
.\Get-ProductKey.ps1 localhost
.\Get-ProductKey.ps1 dc1
I have run powershell with administrator rights, and i have tried it on several servers.... We are running Windows 2008 R2
What am i missing ? or is there another script that is better ?
Thanks for answers
/R
Andreas
You have to dot source the script in order to load the function into the current session.
. .\Get-ProductKey.ps1Get-ProductKey -Computername 'server'
Boe Prox
Blog | PoshWSUS | PoshPAIG | PoshChat
Friday, January 17, 2014 2:14 PM
I have tried to run this script in several iterations. With the extra DOT, without the extra DOT, with the computer name, and without the computer name. Each time I have run the script I get no results or response. Does anyone have any suggestions?
Thursday, September 3, 2015 6:50 PM
Same for me. No output. I've tried several scripts now, all with this result. Not sure what I'm doing wrong that others can get it to work.
Wednesday, September 13, 2017 4:28 PM
this worked on my pc for a remote pc.
run powershell as admin and type the following:
wmic /user:<admin user of network> /node:<pc name on network> os get "SerialNumber"
of course remove brackets AND "SerialNumber" (keep it the way its written)
in my example would be:
wmic /user:jc1_admin /node:pc00202 os get "SerialNumber"
it will prompt for password once you hit enter.