PoshCode Logo PowerShell Code Repository

OEM License by AlphaSun 12 months ago
embed code: <script type="text/javascript" src="http://PoshCode.org/embed/6292"></script>download | new post

This script is for use with MDT. It was written in order to re-image OEM laptops with a clean OS and re-use the preinstalled Windows product key. The script will attempt to pull the OEM product key from WMI and, if available, use slmgr.vbs to install that product key. The same Windows version and edition must be used, otherwise this script will fail. If an OEM key is not found in WMI, the script attempts to determine the version of Windows and use slmgr.vbs to install the generic key for the corresponding version. I have only listed the more common versions of Windows.

The complete list of OperatingSystemSKU numbers can be found here: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724358(v=vs.85).aspx

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!! THE KEYS LISTED IN THIS SCRIPT ARE GENERIC (KMS) KEYS PROVIDED BY MICROSOFT. !!!
!!! THEY ARE INSTALL-ONLY KEYS AND CANNOT BE ACTIVATED. !!!
!!! https://technet.microsoft.com/en-us/library/jj612867.aspx !!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  1. #Get the OEM product key from WMI
  2. $ProductKey = $(wmic path softwarelicensingservice get OA3xOriginalProductKey)[2]
  3. #Get the Operating System SKU (Edition) from WMI
  4. $OSSKU = (Get-WMIObject Win32_OperatingSystem).OperatingSystemSKU
  5.  
  6. IF ($ProductKey -like "*error*") {
  7. <# Keys used in this section are generic keys for installation. None of these
  8. keys can be activated.
  9.  
  10. Reference: http://pastebin.com/SyeWcnKq
  11. Reference: https://technet.microsoft.com/en-us/library/jj612867.aspx
  12.  
  13. These keys are used if Line 2 returns an error. #>
  14.  
  15.         # Version: Windows 8.1 Core
  16.         IF ($OSSKU -eq 101) {
  17.                 cscript C:\Windows\System32\slmgr.vbs -ipk 334NH-RXG76-64THK-C7CKG-D3VPT
  18.                 EXIT }
  19.  
  20.         # Version: Windows 8.1 Core Single Language
  21.         ELSEIF ($OSSKU -eq 100) {
  22.                 cscript C:\Windows\System32\slmgr.vbs -ipk Y9NXP-XT8MV-PT9TG-97CT3-9D6TC
  23.                 EXIT }
  24.  
  25.         # Version: Windows 8.1 Professional
  26.         ELSEIF ($OSSKU -eq 48) {
  27.                 cscript C:\Windows\System32\slmgr.vbs -ipk GCRJD-8NW9H-F2CDX-CCM8D-9D6T9
  28.                 EXIT }
  29.  
  30.         # Version: Windows 8.1 Professional with Windows Media Center
  31.         ELSEIF ($OSSKU -eq 103) {
  32.                 cscript C:\Windows\System32\slmgr.vbs -ipk GBFNG-2X3TC-8R27F-RMKYB-JK7QT
  33.                 EXIT }
  34.  
  35.         # Version: Windows 8.1 Enterprise
  36.         ELSEIF ($OSSKU -eq 4) {
  37.                 cscript C:\Windows\System32\slmgr.vbs -ipk FHQNR-XYXYC-8PMHT-TV4PH-DRQ3H
  38.                 EXIT }
  39.  
  40.         # Version: Other or Not Defined
  41.         ELSE {
  42.                 ECHO "The edition of the operating system either does not match a defined edition in the script, or is not defined in WMI. The script will end."
  43.                 EXIT }
  44.         }
  45.  
  46. ELSE {
  47. <# This block will apply the OEM product key from the MSDM table of ACPI and activate it. #>
  48.  
  49.         cscript C:\Windows\System32\slmgr.vbs -ipk $ProductKey
  50.         cscript C:\Windows\System32\slmgr.vbs -ato
  51.         EXIT }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me