Tag Archives: cmdlet

Fix: Cannot run Executables with parameters using PowerShell

When running a command in-line PowerShell with parameters usually you would do this like & "ipconfig.exe /all". When you run it like that you will get the error saying that it is not recognized.

& : The term 'ipconfig.exe /all' 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.

At line:1 char:3
+ & "ipconfig.exe /all"
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (ipconfig.exe /all:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

This happens due to the fact that the parameters are causing this error. We need to split the parameters from the actual command by running them as below

$Exec = "ipconfig.exe"
$Parm = "/all"
$Parm = $Parm.Split(" ")
& "$Exec" $Parm

 

(24)