通过PowerShell运行.cmd文件

 GUOQIFENG_534 发布于 2023-02-12 14:31

我试图使用PowerShell在远程服务器上运行.cmd文件.

在我的.ps1脚本中我试过这个:

C:\MyDirectory\MyCommand.cmd

它导致此错误:

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

还有这个

Invoke-Command C:\MyDirectory\MyCommand.cmd

导致此错误:

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

我不需要将任何参数传递给PowerShell脚本.我正在寻找的正确语法是什么?

2 个回答
  • Invoke-Item 将查找文件类型的默认处理程序并告诉它运行它.

    它与在资源管理器中双击文件或使用相同基本相同start.exe.

    2023-02-12 14:32 回答
  • 尝试调用cmd /c C:\MyDirectory\MyCommand.cmd- 这应该工作.

    2023-02-12 14:33 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有