0

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

2
  • What did you do and what results you get? Commented Feb 12, 2015 at 11:10
  • @PetSerAl please see above Commented Feb 12, 2015 at 11:19

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

1 Comment

This is the right answer. Accepting Answers.
3

This works for me

$args1 = "argument1"
$args2 = "argument2"

& "C:\Temp\testcmd.cmd" $args1 $args2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.