run command quietly start-process

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

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.


Thanks. That seems like a much better solution.

there is an:

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,

Hi Shane,

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

$x = Get-WmiObject SoftwarelicensingService

Hopefully that helps.

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