Windows 10 Subscription Activation via Powershell

%3CLINGO-SUB%20id%3D%22lingo-sub-698580%22%20slang%3D%22en-US%22%3EWindows%2010%20Subscription%20Activation%20via%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-698580%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20recently%20purchased%20E3%20Subscription%20licenses%20for%20Windows%2010.%20Microsoft's%20documentation%20states%20for%20exisiting%20enterprise%20deployments%2C%20the%20following%20script%20should%20be%20ran%20via%20a%20command%20line%3A%3C%2FP%3E%3CPRE%3E%40echo%20off%0AFOR%20%2FF%20%22skip%3D1%22%20%25%25A%20IN%20('wmic%20path%20SoftwareLicensingService%20get%20OA3xOriginalProductKey')%20DO%20%20(%20%0ASET%20%22ProductKey%3D%25%25A%22%0Agoto%20InstallKey%0A)%0A%0A%3AInstallKey%0AIF%20%5B%25ProductKey%25%5D%3D%3D%5B%5D%20(%0Aecho%20No%20key%20present%0A)%20ELSE%20(%0Aecho%20Installing%20%25ProductKey%25%0Achangepk.exe%20%2FProductKey%20%25ProductKey%25%0A)%3C%2FPRE%3E%3CP%3E%26nbsp%3BI'm%20attempting%20to%20re-write%20this%20in%20powershell%20so%20we%20can%20use%20it%20as%20a%20remediation%20step%20in%20a%20configuration%20baseline%20in%20SCCM.%20Below%20is%20the%20powershell%20script%20I%20wrote%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24ProductKey%20%3D%20(Get-CimInstance%20-ClassName%20SoftwareLicensingService).OA3xOriginalProductKey%3C%2FP%3E%3CP%3Eif%20(%24ProductKey)%7B%3CBR%20%2F%3Estart-process%20c%3A%5CWindows%5CSystem32%5CchangePK.exe%20-ArgumentList%20%22%2FProductKey%20%24ProductKey%22%3CBR%20%2F%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20script%20runs%20without%20error%2C%20but%20it's%20not%20actually%20completing%20the%20intended%20task%20(activating%20the%20embedded%20windows%2010%20pro%20key).%20I'm%20not%20sure%20where%20I'm%20going%20wrong.%20I'm%20pretty%20new%20to%20powershell%20so%20any%20assistance%20would%20be%20greatly%20appreciated.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-698580%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESystem%20Center%20Configuration%20Manager%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-708306%22%20slang%3D%22en-US%22%3ERe%3A%20Windows%2010%20Subscription%20Activation%20via%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-708306%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F183672%22%20target%3D%22_blank%22%3E%40Pat%20O'Neil%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYour%20if%20statement%20appears%20to%20be%20missing%20an%20evaluation.%26nbsp%3B%20As%20you%20have%20it%20originally%20you%20have%20this%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eif(%24ProductKey)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20in%20effect%2C%20to%20quote%2C%20%22if%20Product%20Key%20what%3F%22.%26nbsp%3B%20What%20do%20you%20want%20product%20key%20to%20be%3F%26nbsp%3B%20I%20would%20say%20you%20want%20the%20script%20block%20below%20to%20run%20if%20the%20product%20key%20is%20not%20null%2Femtpy%2C%20correct%3F%26nbsp%3B%20So%20something%20like%20this%20might%20work%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24ProductKey%20%3D%20(Get-CimInstance%20-ClassName%20SoftwareLicensingService).OA3xOriginalProductKey%3C%2FP%3E%3CP%3Eif%20(%24null%20-ne%20%24ProductKey)%3C%2FP%3E%3CP%3E%7B%3CBR%20%2F%3Estart-process%20c%3A%5CWindows%5CSystem32%5CchangePK.exe%20-ArgumentList%20%22%2FProductKey%20%24ProductKey%22%3CBR%20%2F%3E%7D%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-718158%22%20slang%3D%22en-US%22%3ERe%3A%20Windows%2010%20Subscription%20Activation%20via%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-718158%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F231623%22%20target%3D%22_blank%22%3E%40Graham%20Watts%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20the%20response.%20I%20made%20the%20change%20based%20on%20your%20suggestion%20and%20what%20this%20did%20was%20pull%20up%20the%20GUI%20version%20of%20the%20windows%20key%20activation%20where%20it%20asks%20to%20manually%20enter%20the%20key.%20Progress%2C%20you%20could%20say%2C%20but%20this%20script%20needs%20to%20be%20silent%20and%20input%20that%20information%20on%20it's%20own.%20This%20gives%20me%20something%20to%20work%20on%2C%20but%20if%20you%20have%20any%20more%20suggestions%2C%20I%20would%20greatly%20appreciate%20it.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-719326%22%20slang%3D%22en-US%22%3ERe%3A%20Windows%2010%20Subscription%20Activation%20via%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-719326%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F183672%22%20target%3D%22_blank%22%3E%40Pat%20O'Neil%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOK%2C%20I'll%20admit%20I%20didn't%20validate%20the%20actual%20process%20you%20were%20running%20initially%3B%20it%20looked%20visually%20OK%20at%20a%20first%20glance.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESome%20quick%20playing%20shows%20that%20changePK.exe%20seems%20to%20suck%20when%20called%20via%20Start-Process%20or%20Invoke-Expression.%26nbsp%3B%20So%2C%20what%20I've%20done%20instead%20is%20switch%20to%20another%20licensing%20utility%20instead%2C%20slmgr.vbs.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETry%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24ProductKey%20%3D%20(Get-CimInstance%20-ClassName%20SoftwareLicensingService).OA3xOriginalProductKey%3C%2FP%3E%3CP%3Eif%20(%24null%20-ne%20%24ProductKey)%3C%2FP%3E%3CP%3E%7B%3C%2FP%3E%3CP%3EStart-Process%20-FilePath%20%22c%3A%5CWindows%5CSystem32%5Cslmgr.vbs%22%20-ArgumentList%20%22%2Fipk%20%24ProductKey%22%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-725517%22%20slang%3D%22en-US%22%3ERe%3A%20Windows%2010%20Subscription%20Activation%20via%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-725517%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F231623%22%20target%3D%22_blank%22%3E%40Graham%20Watts%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUsing%20slmgr.vbs%20doesn't%20work%20because%20it%20speaks%20to%20the%20KMS%20server%2C%20which%20is%20what%20has%20to%20be%20avoided.%20When%20changing%20the%20script%2C%20it%20attempts%20to%20validate%20the%20key%20and%20returns%20an%20incorrect%20key%20error%20message.%20This%20doesn't%20allow%20the%20embedded%20key%20to%20activate%2C%20which%20is%20what%20the%20subscription%20licensing%20requires.%20All%20of%20this%20could%20be%20avoided%20if%20we%20could%20simply%20force%20our%20entire%20company%20to%20log%20in%20with%20their%20azure%20credentials%2C%20but%20I'm%20not%20sure%20we%20can%20force%203000%2B%20users%20to%20make%20that%20swap.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-725729%22%20slang%3D%22en-US%22%3ERe%3A%20Windows%2010%20Subscription%20Activation%20via%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-725729%22%20slang%3D%22en-US%22%3EFigured%20it%20out.%20Had%20to%20add%20-filepath%20after%20start-process.%20It%20now%20activates%20the%20embedded%20key!%20Thank%20you%20so%20much!%3CBR%20%2F%3E%3CBR%20%2F%3E%24ProductKey%20%3D%20(Get-CimInstance%20-ClassName%20SoftwareLicensingService).OA3xOriginalProductKey%3CBR%20%2F%3E%3CBR%20%2F%3Eif%20(%24null%20-ne%20%24ProductKey)%3CBR%20%2F%3E%3CBR%20%2F%3E%7B%3CBR%20%2F%3Estart-process%20-filepath%20c%3A%5CWindows%5CSystem32%5CchangePK.exe%20-ArgumentList%20%22%2FProductKey%20%24ProductKey%22%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-727648%22%20slang%3D%22en-US%22%3ERe%3A%20Windows%2010%20Subscription%20Activation%20via%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-727648%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F183672%22%20target%3D%22_blank%22%3E%40Pat%20O'Neil%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EInteresting!%26nbsp%3B%20I%20could%20have%20sworn%20I%20tried%20formatting%20the%20command%20fully%20with%20the%20-FilePath%20in%20my%20lab%20and%20it%20didn't%20work%2C%20hence%20I%20change%20over%20at%20all.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20glad%20we%20got%20there%20in%20the%20end!%26nbsp%3B%20%3A)%3C%2Fimg%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-728387%22%20slang%3D%22en-US%22%3ERe%3A%20Windows%2010%20Subscription%20Activation%20via%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-728387%22%20slang%3D%22en-US%22%3EThe%20command%20won't%20work%20if%20you're%20running%20it%20on%20a%20VM%20or%20a%20machine%20without%20an%20embedded%20key%20in%20the%20mobo%2C%20so%20perhaps%20that's%20why%3F%3CBR%20%2F%3E%3CBR%20%2F%3EThank%20you%20again%20for%20your%20assistance.%20I%20appreciate%20it%20quite%20a%20bit.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-730079%22%20slang%3D%22en-US%22%3ERe%3A%20Windows%2010%20Subscription%20Activation%20via%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-730079%22%20slang%3D%22en-US%22%3EThat%20could%20be%20it.%3CBR%20%2F%3E%3CBR%20%2F%3EEither%20way%2C%20glad%20you%20got%20what%20you%20need.%3CBR%20%2F%3E%3CBR%20%2F%3ENo%20problem%2C%20any%20time!%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-776071%22%20slang%3D%22en-US%22%3ERe%3A%20Windows%2010%20Subscription%20Activation%20via%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-776071%22%20slang%3D%22en-US%22%3E%3CP%3E%3CBR%20%2F%3ETotally%20native%20Powershell%20%26amp%3B%20remote%20activation%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Ecls%0A%24computer%20%3D%20%24env%3Acomputername%0A%24ProductKey%20%3D%20(Get-CimInstance%20-ClassName%20SoftwareLicensingService).OA3xOriginalProductKey%0Aif%20(%24ProductKey)%20%7B%0A%20%20%20%20write-debug%20%22set%20%24ProductKey%22%20%0A%20%20%20%20%24service%20%3D%20get-wmiObject%20-query%20%22select%20*%20from%20SoftwareLicensingService%22%20-computername%20%24computer%0A%20%20%20%20%24service.InstallProductKey(%24ProductKey%20)%0A%20%20%20%20%24service.RefreshLicenseStatus()%0A%20%20%20%20%24service.RefreshLicenseStatus()%0A%20%20%20%20write-debug%20%22done%22%0A%7Delse%7B%0A%20write-debug%20'Key%20not%20found!'%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

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.

8 Replies
Highlighted

@Pat O'Neil 

 

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"
}

Highlighted

@Graham Watts 

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.

Highlighted

@Pat O'Neil 

 

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"

}

Highlighted
Figured it out. Had to add -filepath after start-process. It now activates the embedded key! Thank you so much!

$ProductKey = (Get-CimInstance -ClassName SoftwareLicensingService).OA3xOriginalProductKey

if ($null -ne $ProductKey)

{
start-process -filepath c:\Windows\System32\changePK.exe -ArgumentList "/ProductKey $ProductKey"
}

Highlighted

@Pat O'Neil 

 

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!  :)

Highlighted
The command won't work if you're running it on a VM or a machine without an embedded key in the mobo, so perhaps that's why?

Thank you again for your assistance. I appreciate it quite a bit.
Highlighted
That could be it.

Either way, glad you got what you need.

No problem, any time!
Highlighted


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!'
}