diff --git a/Services Scripts/auto start agent service.ps1 b/Services Scripts/auto start agent service.ps1 new file mode 100644 index 0000000..60ecb5b --- /dev/null +++ b/Services Scripts/auto start agent service.ps1 @@ -0,0 +1,27 @@ +$serviceName = "Windows Agent Maintenance Service" + +$arrService = Get-Service -Name $serviceName + +while ($arrService.Status -eq 'Running') { + Write-Host $serviceName $arrService.status + Start-Service $serviceName + Write-Host $serviceName $arrService.status + + # Wait a short period before checking the service + Start-Sleep -seconds 5 + + $arrService.Refresh() + Write-Host $serviceName $arrService.status + + + if ($arrService.Status -eq 'Running') { Continue } + # Attempt to restart service + Start-Service $serviceName + Write-Host $serviceName $arrService.status + + # Wait a short period before checking the service + Start-Sleep -seconds 10 + + $arrService.Refresh() + Write-Host $serviceName $arrService.status +} \ No newline at end of file