我想通过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/