Powershell: call an exe with parameters from items in an array? Powershell: call an exe with parameters from items in an array? powershell powershell

Powershell: call an exe with parameters from items in an array?


When you use the call operator & the string following it must name only the command to be executed - not any parameters. With what you have configured you can use Invoke-Expression instead e.g.:

iex $command[0]

One warning about Invoke-Expression, be careful using this command if any input comes from the user as it can be used to inject unwanted commands e.g.:

Read-Host "Enter commit value"Enter commit value: apphost; remove-item c:\ -r -force -ea 0 -confirm:0 #


Well, i'm a year late to a party, but you can also do this:

new-alias -name Monkey -value "$env:windir\system32\inetsrv\APPCMD.exe"


Even later: I think this answer and this other answer by user Roman Kuzmin closely address this issue, by storing executable name in a variable and all its parameters in an array.