我需要一个powershell脚本,我可以从主机运行,它将重新启动远程计算机上的exe(如excel或其他东西)。
我尝试过使用拥有,调用命令和psexec,但无济于事。我甚至想到了一种在主机上的方法,并尝试执行远程服务器上的脚本。我没有得到任何错误,这使得很难知道发生了什么/如果它发生了。
我在我的脚本中试过这个:&EXCEL.exe
我希望应用程序在远程计算机上打开。
这解决了我的问题。我做了一个我最终做的通用版本:
$remoteComputer = "ComputerName"
$appLocation = "C:\Windows\notepad"
$taskName = "openNotepad"
$delay = (get-date).AddMinutes(1) #adds 1 minute to the current time
$newTime = get-date $delay -format HH:mm:ss #24 HR format
echo (get-date -Uformat %T)
echo $newTime #compare the time difference
$null = schtasks /create /s $remoteComputer /TN $taskName /TR $appLocation /SC ONCE /ST $newTime
start-sleep -s 65 #schtasks can't perform on the same minute, and needs a wait time before it will delete the task
$null = schtasks /delete /s $remoteComputer /TN $taskName /f