Run a .cmd file through PowerShell

Viewed 121225

I am trying to run a .cmd file on a remote server with PowerShell.

In my .ps1 script I have tried this:

C:\MyDirectory\MyCommand.cmd

It results in this error:

C:\MyDirectory\MyCommand.cmd is not recognized as the name of a cmdlet,
function, script file, or operable program.

And this

Invoke-Command C:\MyDirectory\MyCommand.cmd

results in this error:

Invoke-Command : Parameter set cannot be resolved using the specified named
parameters.

I do not need to pass any parameters to the PowerShell script. What is the correct syntax that I am looking for?

6 Answers

The code is not C:\MyDirectory\MyCommand.cmd its C:/MyDirectory/MyCommand.cmd opposit /

if you are in the same folder, then code would be:- ./MyCommand.cmd In powershell. In CMD : MyCommand

First you can reach till that folder: cd 'C:\MyDirectory' and then use: ./MyCommand.cmd

Related