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

时间:2013-12-06 14:24:54

标签: file powershell cmd

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

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

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

1 个答案:

答案 0 :(得分:0)

您的脚本块应为:

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

查看Start-Process cmdlet and the verb runas,即可找到您。 (可选)使用该cmdlet包含-wait以等待cmd在返回之前完成。