file - Powershell以管理员身份启动cmd文件

标签 file powershell cmd

我想通过Powershell在远程服务器上执行.cmd文件。这很好用:

Invoke-Command -ComputerName <computerName> -credential $cred -ScriptBlock {&"C:\...\Script.cmd"}

但是,以“管理员身份”运行Script.cmd的语法是什么?

最佳答案

您的脚本块应为:

-Scriptblock {Start-Process -Path "C:\...\Script.cmd" -Verb Runas}

查看Start-Process cmdlet and the verb runas,它将带您到达那里。 (可选)在该cmdlet中包括-wait,以等待该cmd完成后再返回。

关于file - Powershell以管理员身份启动cmd文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20426235/

相关文章:

java - 如何使用相对路径-Java

java - 使用 ant 创建构建文件

sql-server - 为 Dacpac 和 Powershell 脚本创建 Nuget 包

windows - Windows CMD批处理时间戳记(秒)

ant - 如何使用命令行参数压缩文件夹的内容?

c - 使用双指针和 malloc 读取文件

Python 读取 .txt 文件头

javascript - JSON.解析 : unexpected character at line 1 column 1 of the JSON data in Firefox only

powershell - 如何从powershell为cmd脚本保留彩色输出(stdout和stderr)?

windows - Echo 在我的 Windows 批处理脚本中无法正常工作