0

At the end of a powershell script, i wanted to starta cmd script. In order to proceed, i added this : Invoke-Command cmd /c $destinationn\02_creation_de_repertoire.cmd

Result :

Invoke-Command : Impossible de trouver un paramètre positionnel acceptant l'argument «
C:\Users\moamg\Desktop\SPO\02_creation_de_repertoire.cmd».
Au caractère C:\Users\moamg\Desktop\scripts_global\01_install_spo1.ps1:32 : 1
+ Invoke-Command cmd /c $destinationn\02_creation_de_repertoire.cmd
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument : (:) [Invoke-Command], ParameterBindingExcept
   ion
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.Invo
   keCommandCommand

Any clue ? I started ./FILE.cmd, or FILE.cmd from powershell, and it work. But in the script, it don't.

3
  • The version of Invoke-Command with the -FilePath takes its arguments as an array. So `Invoke-Command -filepath Path-To-Cmd 'arg1','arg2'. Commented Dec 19, 2018 at 13:30
  • When using a cmdlet always check MS Official doc and/or Get-Help [cmdlet] Commented Dec 19, 2018 at 13:39
  • You could try a plain cmd.exe /c $destinationn\02_creation_de_repertoire.cmd without the initial Invoke-Command Commented Dec 19, 2018 at 13:49

2 Answers 2

1

The cmdlet excepts a script block:

Invoke-Command { cmd /c $destinationn\02_creation_de_repertoire.cmd }

Or explicitly:

Invoke-Command -ScriptBlock { cmd /c $destinationn\02_creation_de_repertoire.cmd }
Sign up to request clarification or add additional context in comments.

1 Comment

As an addition: the script must be enclosed in something, otherwise parameters for the script could be confused with parameters of Invoke-Command by the parser.
0

Maybe you can use Start-Process -FilePath $destinationn\02_creation_de_repertoire.cmd instead. Try help Start-Process from your command prompt for full syntax.

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.