r/usefulscripts • u/feldrim • Oct 26 '22
[PowerShell] Using PowerShell for KMS activation, instead of slmgr.vbs
It's a drop-in replacement for slmgr.vbs script. Today I stumbled upon the script I created and shared here 2 years ago. I checked that and made some improvements.
The differences from slmgr.vbs:
You can provide an array of computer names, and it is up to you how you get them. It's just PowerShell.
It works on PowerShell version 5.0 and above. It means PowerShell 7.0 is ok, too.
It uses WinRM for remote computers. Check if remote computers are accessible over WinRM.
It includes a list of KMS keys, so that you don't have to for most of them. It covers some of the versions, not all of them.
It works even if you disabled
cscriptandwscript.The code is documented and readable, so that you can improve according to your needs.
Gist:
It's a drop-in replacement for slmgr.vbs script (github.com)
2
u/branhama Oct 26 '22
I can see this as being useful, thanks for the post.
2
u/feldrim Oct 26 '22
It was important for us back then. Troubleshooting required
slmgr.vbs /atoyet we disabledcscriptandwscriptdue to security hardening. I had to come up with a quick and working solution.Thanks for the comment.
1
u/feldrim Oct 27 '22
Please inform me if you get any issues, errors, edge cases or simple mistakes I could not detect in my environment.
1
u/FarEconomics5977 Nov 26 '24
I'm not sure it works with Windows 11. The "SetKeyManagementServiceMachine" and "SetKeyManagementServicePort" methods are no longer found in the "SoftwareLicensingService".
1
u/feldrim Nov 26 '24
Hi. It's been a while and I haven't tested it on any Windows 11. Can you provide the verbose log or any other data that can help?
1
u/feldrim Dec 06 '24
Hi. Is it possible if you can share the slmgr.vbs file content via a Github gist or anything? It'd take some time to install a Windows 11 for just one file.
1
u/Zulgrib Feb 26 '23
Maybe an error reading the script, but the ability to set the kms server ip+port is missing while slmgr.vbs allowed that.
I know you can specify the server with the _vlmcs subdomain, but dns issues happen.
Thank you for sharing.
2
u/feldrim Feb 26 '23 edited Feb 26 '23
Hi. It's relatively easy to add this functionality. Back then, I did not have this option in mind. In my current work environment, I do not have a test option for that. I can spend some time to add the functionality but I need someone to test that. Or I will have to create a lab environment which would take 5 to 10x time of actual development for a little added value.
Edit: Anyway, I added the functionality. It is a simple addition but it needs to be tested.
1
u/Zulgrib Feb 27 '23
Thank you for your time, I will test it and report back when my new server arrive.
2
u/Not_Freddie_Mercury Oct 26 '22
Great timing, as suddenly we're getting lots of tickets of expired Enterprise licenses.
I made a quick and basic script to deal with it, but I sure as hell will be taking pointers from yours. Cheers!
5
u/feldrim Oct 26 '22
If you need to activate, you had to:
Find the key for your product
Type
slmgr.vbs /ipk <5x5 key for the product>Type
slmgr.vbs /atoRepeat the same for each host locally
With this cmdlet, you trigger the activation by just typing
Start-WindowsActivation -Computer <array of hostnames>remotely if WinRM is configured on the target. Or you can just do the same locally withStart-WindowsActivation.