Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Torxsmind/a0d9cc2eb12e328f75cc067adbd966ec to your computer and use it in GitHub Desktop.

Select an option

Save Torxsmind/a0d9cc2eb12e328f75cc067adbd966ec to your computer and use it in GitHub Desktop.
Powershell to create a automated service restart
$settings = New-ScheduledTaskSettingsSet `
–AllowStartIfOnBatteries `
–DontStopIfGoingOnBatteries `
-Hidden `
-ExecutionTimeLimit (New-TimeSpan -Minutes 5) `
-RestartCount 3
$Time = New-ScheduledTaskTrigger -At 01:00 -Daily
$PS = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "Restart-Service -Name Spooler"
Register-ScheduledTask -TaskName "Restart-Service-Spooler" -Trigger $Time -Action $PS -Settings $settings -User System
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment