force kms sync with powershell hangs

220 Views Asked by At

I have a command in my script.ps1 which is run by a next build step in tfs 2015. I then navigate to the location of office, run the command to force a KMS push like this:

cmd.exe dir "C:\apps\MSOffice\Office15\"
cmd.exe "cscript ospp.vbs /act"

It gets executed but then it just hangs and nothing happens. If I execute the command by hand it works without problems. This only occurs if I do it through powershell - running the command by hand works as intended.

2

There are 2 best solutions below

0
On BEST ANSWER

thanks Micky!, /C helped me debugging.

solution is like this:

cmd.exe /c "cd C:\apps\MSOffice\Office15\"
cmd.exe /c "cscript.exe C:\apps\MSOffice\Office15\ospp.vbs /act"

need to execute the script VB handler separately from the VB script. BTW: the reason why im doing this is because i have a build task that will execute this upon 20 build machines simultaneously.

0
On

Not sure why you would call CMD from PowerShell to execute commands that PowerShell can execute directly.

Anyway

Use /C to return when the command is performed

cmd.exe /C dir "C:\apps\MSOffice\Office15\"
cmd.exe /C "cscript ospp.vbs /act"