Reputation: 49
I am a complete novice when it comes to powershell and something that seems like it would be so simple is completely escaping me...
I can't run an old .cmd file which I need to call with a parameter. When using cmd.exe I would navigate to the directory where the .cmd is held,
cd C:\MyDirectory\BlahBlah1
Then type the name of my script followed by the parameter I want to pass
MyScript.cmd Parameter1
The cmd script would then run with the specified parameter no issues. How would I launch the .cmd script with the specified parameter from powershell?
I have been trying, cd C:\MyDirectory\BlahBlah1 Which takes me to my directory with no issues.. Then,
Invoke-Item MyScript.cmd Parameter1
With result
Invoke-Item : A positional parameter cannot be found that accepts argument 'Parameter1'. At line:1 char:12 + Invoke-Item <<<< MyScript.cmd bup + CategoryInfo : InvalidArgument: (:) [Invoke-Item], ParameterBindingException + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeItemCommand
Upvotes: 0
Views: 4490
Reputation: 121
This works for me
$args1 = "argument1"
$args2 = "argument2"
& "C:\Temp\testcmd.cmd" $args1 $args2
Upvotes: 3
Reputation: 22102
You can execute .cmd
files same way as you do it in cmd
, but you have to explicitly specify to look for .cmd
in current directory:
.\MyScript.cmd Parameter1
Upvotes: 4