1

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?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Austin Harris
  • 5,150
  • 6
  • 26
  • 39

2 Answers2

2

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

Community
  • 1
  • 1
lloyd
  • 1,683
  • 2
  • 19
  • 23
2

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"
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328