Jun 17 2019 04:52 PM
We recently purchased E3 Subscription licenses for Windows 10. Microsoft's documentation states for exisiting enterprise deployments, the following script should be ran via a command line:
@echo off FOR /F "skip=1" %%A IN ('wmic path SoftwareLicensingService get OA3xOriginalProductKey') DO ( SET "ProductKey=%%A" goto InstallKey ) :InstallKey IF [%ProductKey%]==[] ( echo No key present ) ELSE ( echo Installing %ProductKey% changepk.exe /ProductKey %ProductKey% )
I'm attempting to re-write this in powershell so we can use it as a remediation step in a configuration baseline in SCCM. Below is the powershell script I wrote:
$ProductKey = (Get-CimInstance -ClassName SoftwareLicensingService).OA3xOriginalProductKey
if ($ProductKey){
start-process c:\Windows\System32\changePK.exe -ArgumentList "/ProductKey $ProductKey"
}
The script runs without error, but it's not actually completing the intended task (activating the embedded windows 10 pro key). I'm not sure where I'm going wrong. I'm pretty new to powershell so any assistance would be greatly appreciated.
Jun 19 2019 12:51 PM
Your if statement appears to be missing an evaluation. As you have it originally you have this
if($ProductKey)
So in effect, to quote, "if Product Key what?". What do you want product key to be? I would say you want the script block below to run if the product key is not null/emtpy, correct? So something like this might work
$ProductKey = (Get-CimInstance -ClassName SoftwareLicensingService).OA3xOriginalProductKey
if ($null -ne $ProductKey)
{
start-process c:\Windows\System32\changePK.exe -ArgumentList "/ProductKey $ProductKey"
}
Jun 24 2019 12:24 PM
Thanks for the response. I made the change based on your suggestion and what this did was pull up the GUI version of the windows key activation where it asks to manually enter the key. Progress, you could say, but this script needs to be silent and input that information on it's own. This gives me something to work on, but if you have any more suggestions, I would greatly appreciate it.
Jun 25 2019 02:44 AM
OK, I'll admit I didn't validate the actual process you were running initially; it looked visually OK at a first glance.
Some quick playing shows that changePK.exe seems to suck when called via Start-Process or Invoke-Expression. So, what I've done instead is switch to another licensing utility instead, slmgr.vbs.
Try this:
$ProductKey = (Get-CimInstance -ClassName SoftwareLicensingService).OA3xOriginalProductKey
if ($null -ne $ProductKey)
{
Start-Process -FilePath "c:\Windows\System32\slmgr.vbs" -ArgumentList "/ipk $ProductKey"
}
Jun 27 2019 11:43 AM
Jun 28 2019 02:35 AM
Interesting! I could have sworn I tried formatting the command fully with the -FilePath in my lab and it didn't work, hence I change over at all.
I'm glad we got there in the end! :)
Jun 28 2019 09:17 AM
Jun 30 2019 12:43 AM
Jul 27 2019 02:48 AM - edited Jul 27 2019 02:51 AM
Totally native Powershell & remote activation:
cls
$computer = $env:computername
$ProductKey = (Get-CimInstance -ClassName SoftwareLicensingService).OA3xOriginalProductKey
if ($ProductKey) {
write-debug "set $ProductKey"
$service = get-wmiObject -query "select * from SoftwareLicensingService" -computername $computer
$service.InstallProductKey($ProductKey )
$service.RefreshLicenseStatus()
$service.RefreshLicenseStatus()
write-debug "done"
}else{
write-debug 'Key not found!'
}