Austin Harris
Austin Harris

Reputation: 5410

Syntax for running executables?

I am trying to run this from the PowerShell 3 ISE:

&"C:\inetpub\htpasswd.exe -bc C:\inetpub\wwwroot\xyz\password\passMD5.txt sm88555 sm88999"

but get this error:

is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I think PowerShell stops evaluating this correctly after the first space?

Upvotes: 1

Views: 229

Answers (2)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200293

The call operator doesn't interpret entire commandlines/expressions. That is what Invoke-Expression is for. Separate the arguments from the command (and from each other) if you want to use the call operator:

& "C:\inetpub\htpasswd.exe" -bc "C:\inetpub\wwwroot\xyz\password\passMD5.txt" "sm88555" "sm88999"

Upvotes: 2

lloyd
lloyd

Reputation: 1811

iex - Invoke-Expression I use when & fails

$htPassword = "C:\inetpub\htpasswd.exe"
$htParams = "C:\inetpub\wwwroot\xyz\password\passMD5.txt sm88555 sm88999"
Invoke-Expression -Command "$htPassword $htParams"

myeval handles both quite well by joel-b-fant

Upvotes: 2

Related Questions