Task Scheduler
Aus Wiki-WebPerfect
Version vom 27. Oktober 2021, 08:56 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." $Command = "& {If (!(Get-Process splunk-winevtlog)) {Restart-Service SplunkForwarder}}" $TaskAction = New-ScheduledTaskAction -Execute "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Argument '-NoProfile -WindowStyle Hidden -Command `"$Command`"" $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