Skip to content

Instantly share code, notes, and snippets.

@NielsS79
Last active June 10, 2023 18:19
Show Gist options
  • Save NielsS79/4b76082ea0eda0264bfbd0f435c0306f to your computer and use it in GitHub Desktop.
Save NielsS79/4b76082ea0eda0264bfbd0f435c0306f to your computer and use it in GitHub Desktop.
Gets the product key stored in UEFI/BIOS and import it.
<#
.SYNOPSIS
Reads the Windows (OEM) product key from firmware (UEFI/BIOS), then imports it via slmgr.
.NOTES
"There are many like it, but this one is mine."
Author: Niels Scheffers <niels.scheffers@etesian.nl>
Last modified: 2022-03-10
#>
Try {
# Get OEM product key from firmware.
$oemProductKey = (Get-WmiObject -Query 'SELECT * FROM SoftwareLicensingService').OA3xOriginalProductKey;
# Import the key.
Invoke-Command -ScriptBlock { slmgr -ipk $oemProductKey; }
}
Catch {
Throw "Failed to set Windows product key.";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment