What is correct way to call this cscript??

I need to do this for five (5) XenApp servers, for now only one for testing.
PowerShell won’t let me run the below line in bold with the cscript in it.

I get this error:
Microsoft ® Windows Script Host Version 5.812
Copyright © Microsoft Corporation. All rights reserved.
Input Error: There is no file extension in “\x1\C$\Program Files\Microsoft Office\Office16\ospp.vbs \dstatus”.
Press Enter to continue…:

There IS a file extension and it’s changing the forward slash to a back slash.
What’s the right way to call this cscript line in PowerShell??

Code below:

cls
#$servers = @('x1,‘x2’,‘x3’,‘x4’,‘x5’)
$servers = @(‘x1’)
foreach ($server in $servers) {
cscript “\$server\C`$\Program Files\Microsoft Office\Office16\ospp.vbs /dstatus”
pause

cscript ospp.vbs /inpkey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX

pause

cscript ospp.vbs /act

pause

}

Use the call operator & like so:

& cscript "\\$server\C$\Program Files\Microsoft Office\Office16\ospp.vbs" "/dstatus"

The call operator does not parse strings so you need to manually ‘tokenize’ the command into pieces with spaces between (no commas). Otherwise the entire line is considered one command rather than a command with additional options/arguments. That’s why you get the file extension error because “… /dstatus” is not an extension.

Thank you 2,348,532 tons!! :slight_smile: :slight_smile:

I did not know of the & call operator nor its requirements.

The script now works properly, plus I added $server at the end to make it work on the remote server.

Now I have:

foreach ($server in $servers) {
& cscript “\$server\C`$\Program Files\Microsoft Office\Office16\ospp.vbs” “/dstatus” $server
pause

cscript ospp.vbs /inpkey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX

pause

cscript ospp.vbs /act

pause

}