Recently, I had a task to do where some clients had three Windows Server 2012R2 remote servers, deployed manually, but we were providing the licenses. Considering the circumstances, I had to resort to
slmgr.vbs in order to activate the remote machines with the MAK key we had for those systems.
The issue there is that the tool hangs. Any operation attempted will attempt to pull up a box, but since I was doing this over a remote PowerShell session, this was nowhere to be found.
After scouring online for a bit, my idea was to reuse the code from
slmgr itself, as its just a simple visual basic script, which has its code laid out in the open. Looking through it though, I saw
wscript was called a few times, which is when I remembered the existence of
cscript. Despite having similar names, the first letter is of importance: cscript runs scripts, supported by Windows internals in a command-line environment, while wscript can run those and some others, in a graphical environment.
So the solution here was obvious. We need to use cscript as our scripting engine. You could create a modified version of slmgr.vbs, where wscript is replaced everywhere, or the easier option is running the following:
This will give you all the commands slmgr can do. So, for example, if you want to check the status of your activation, you can do:
cscript $Env:SystemRoot/System32/slmgr.vbs /dlv
And if you wanted to register a key, this would be:
cscript $Env:SystemRoot/System32/slmgr.vbs /ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
cscript $Env:SystemRoot/System32/slmgr.vbs /ato