Task Scheduler
Aus Wiki-WebPerfect
Version vom 13. September 2021, 11:59 Uhr von Admin (Diskussion | Beiträge)
Create a Task in Windows Task Scheduler
Because of an Splunk Universal Forwarder issue, we had to create a task to check if the subprocess are running after a reboot. If the subprocess is not running, restart the service.
$TaskName = "Splunk Workaround" $TaskDescription = "Restart Splunk Service if splunk-wineventlog.exe is not running." $TaskAction = New-ScheduledTaskAction -Execute "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Argument '-NoProfile -WindowStyle Hidden -command "& If (!(Get-Process splunk-winevtlog)) {Restart-Service SplunkForwarder}"' $TaskTriggers = (New-ScheduledTaskTrigger -AtStartup -RandomDelay (New-TimeSpan -Minutes 5)), (New-ScheduledTaskTrigger -Daily -At '5:00 AM') $TaskSettings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Minutes 5) -RestartCount 3 -RestartInterval (New-TimeSpan -Minutes 1) Register-ScheduledTask -TaskName $TaskName -Description $TaskDescription -Action $TaskAction -Trigger $TaskTriggers -Settings $TaskSettings -User "System" -RunLevel Highest -Force