To retrieve the OEM Windows 10 Product Key which is usually stored within a devices WMI repository you can use the following PowerShell command:
(Get-CimInstance -ClassName SoftwareLicensingService).OA3xOriginalProductKey
To retrieve and then install an OEM Windows 10 Product Key, the following PowerShell can be used:
<#
.DESCRIPTION
Script to activate Windows 10 using OEM licence key
.EXAMPLE
PowerShell.exe -ExecutionPolicy ByPass -File <ScriptName>.ps1
.NOTES
Author(s): Jonathan Conway
Modified: 08/09/2021
Version: 1.0
#>
$OemProductKey = (Get-CimInstance -ClassName "SoftwareLicensingService").OA3xOriginalProductKey
$cscript = 'C:\Windows\System32\cscript.exe'
# Install Product Key
return (Start-Process $cscript -ArgumentList "/B C:\Windows\System32\slmgr.vbs -ipk $OemProductKey" -NoNewWindow -PassThru -Wait).ExitCode
return (Start-Process $cscript -ArgumentList "/B C:\Windows\System32\slmgr.vbs -ato" -NoNewWindow -PassThru -Wait).ExitCode
You can also use WMI to accomplish the same things which is demonstrated in the PowerShell script below:
<#
.DESCRIPTION
Script to activate Windows 10 using OEM licence key
.EXAMPLE
PowerShell.exe -ExecutionPolicy ByPass -File <ScriptName>.ps1
.NOTES
Author(s): Jonathan Conway
Modified: 10/05/2022
Version: 1.0
#>
# Variables
$SLS = Get-CimInstance -ClassName "SoftwareLicensingService"
$OemProductKey = (Get-CimInstance -ClassName "SoftwareLicensingService").OA3xOriginalProductKey
# Display and Activate Product Key
Write-Output "$OemProductKey"
$SLS | Invoke-CimMethod -MethodName "InstallProductKey" -Arguments @{ ProductKey = "$OemProductKey" }
$SLS | Invoke-CimMethod -MethodName "RefreshLicenseStatus"
# JC
