Author Posts

November 22, 2015 at 12:50 pm

I want to run the following command with powershell and wait till it completes before doing the next item

slmgr.vbs -upk

slmgr after it completes the command displays a windows which needs human intervention to click "ok" to close it and complete the process. I need this to work without human intervention. I figured out a way to do it using cscript , but it seems messy. Is there a way to do this without using cscript.

This is the current working method, which seems good

Start-Process "c:\windows\system32\cscript" "c:\windows\system32\slmgr.vbs -upk" -wait

Is there a better way? I do need powershell 2.0 compatibility

November 22, 2015 at 3:24 pm

Hi Shane,

If you're interested in possible other solutions I'd suggest you take a look into the WMI class for SoftwareLicensingService.

 Get-WmiObject SoftwarelicensingService 

This class contains many methods that can mostly replace slmgr. Take a look into the members for the WMI class and see how you go.

Cheers!

November 22, 2015 at 4:07 pm

Thanks. That seems like a much better solution.

November 22, 2015 at 5:25 pm

there is an:
installLicense()
installLicensePackage()

I am having trouble finding documentation I can understand. I have tried the following with both methods.

They say they take a string, so I am guessing it would be like this

PS C:\Users\shane\Desktop> $a.InstallLicense('TOSINV00-TOSINV-2.1.XRM-MS')
Exception calling "InstallLicense" : ""
At line:1 char:1
+ $a.InstallLicense('TOSINV00-TOSINV-2.1.XRM-MS')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WMIMethodException

If I am understanding the error it is the correct syntax but is is failing somewhere else. I am not sure if either of those are the methods I need, but can't see any others. Any suggestions would be appreciated,

November 22, 2015 at 8:38 pm

Hi Shane,

As an example of adding a product key to a workstation you could use something like this:

$x = Get-WmiObject SoftwarelicensingService
$x.InstallProductKey('XXXXX-XXXXX-XXXXX-XXXXX-XXXX')
$x.RefreshLicenseStatus()

Hopefully that helps.

November 22, 2015 at 8:46 pm

Thanks for the help. I am able to install the product key as you mentioned, but am having trouble installing the actual licence file

This is the command I am trying to relplace and get away from slmgr.vba
slmgr.vbs -ilc TOSINV00-TOSINV-2.1.XRM-MS

http://ss64.com/nt/slmgr.html