我正在尝试创建一个任务,该任务在每次事件发生时都会触发。事件正在停止winrm服务,当这种情况发生时,它将触发任务以再次启动它。
我可以使用eventviewer界面执行此操作,但我想从命令行执行操作-此命令是什么?
来源:Windows远程管理
级别:信息
事件ID:212
该任务将启动powershell.exe,参数为ps1脚本
最佳答案
试试这个:
$cred = Get-Credential
$password = $cred.GetNetworkCredential().Password
$command = "PowerShell -NoProfile -ExecutionPolicy RemoteSigned " +
"-WindowStyle Hidden -File 'C:\Script.ps1'"
SCHTASKS /Create /TN "Event Monitor" /TR $command /SC ONEVENT `
/RL Highest /RU $cred.Username /RP $password `
/EC ScriptEvents /MO *[Application/EventID=212]
关于windows - Windows-从命令行为事件创建任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33390035/