我想通过Powershell在远程服务器上执行.cmd
文件。这很有效:
Invoke-Command -ComputerName <computerName> -credential $cred -ScriptBlock {&"C:\...\Script.cmd"}
但是以管理员身份运行Script.cmd
“的语法是什么?
答案 0 :(得分:0)
您的脚本块应为:
-Scriptblock {Start-Process -Path "C:\...\Script.cmd" -Verb Runas}
查看Start-Process cmdlet and the verb runas,即可找到您。 (可选)使用该cmdlet包含-wait
以等待cmd在返回之前完成。