Reputation: 175
So I am trying to run a VBscript via cscript.exe embedded within a powershell script. It keeps erroring out with a permissioning error. While debugging the code, I realized that the exact command will not run in cscript or wscript, but will run from the command prompt. I was under the impression that by default cmd.exe calls wscript to execute VBScript.
this is the code that's failing me.
$hostname = MIA-DC1
$user = contoso\administrator
$password = Pa$$w0rd
cscript.exe c:\windows\system32\slmgr.vbs $hostname $user $password /dlv
I first thought it was the variables that were screwing it up however, all of the following have failed with the same error:
cscript.exe c:\windows\system32\slmgr.vbs MIA-DC1 contoso\administrator Pa$$w0rd /dlv
cscript.exe c:\windows\system32\slmgr.vbs MIA-DC1 "contoso\administrator" Pa$$w0rd /dlv
wscript.exe c:\windows\system32\slmgr.vbs MIA-DC1 contoso\administrator Pa$$w0rd /dlv
wscript.exe c:\windows\system32\slmgr.vbs MIA-DC1 "contoso\administrator" Pa$$w0rd /dlv
However, should I type the command (in any form) into a command prompt, it runs as intended no questions asked.
I'm a bit out of ideas at this point. could someone possibly point me to differences between cmd.exe calling cscript/wscript versus calling it myself?
Thanks so much in advance.
Upvotes: 1
Views: 8277
Reputation: 106
Trying quoting your password:
cscript.exe c:\windows\system32\slmgr.vbs MIA-DC1 "contoso\administrator" 'Pa$$w0rd' /dlv
Cmd doesn't interpret a $ as anything special. Powershell, however, thinks you have a variable named $w0rd and is probably substituting an empty string. Single quotes will prevent the attempted substitution; double quotes will not.
Upvotes: 3