I created a PowerShell script like this one, and saved it to the hard drive as RestartService.ps1
$ServiceName = 'Serenade'
$arrService = Get-Service -Name $ServiceName
while ($arrService.Status -ne 'Running')
{
Start-Service $ServiceName
write-host $arrService.status
write-host 'Service starting'
Start-Sleep -seconds 60
$arrService.Refresh()
if ($arrService.Status -eq 'Running')
{
Write-Host 'Service is now Running'
}
}
Then I opened Task Scheduler, and I created a task that runs this script. The actions for the script are like this:
- Actions: Start a program
- Program/Script: PowerShell.exe
- Add arguments: -ExecutionPolicy Bypass -File RestartService.ps1 -skipadmincheck
- Start in: D:\PowerShell
The "Start in" location is where you saved the PowerShell script.
Now you have a scheduled task that will check this service on the schedule that you define.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.