27 lines
789 B
PowerShell
27 lines
789 B
PowerShell
|
|
$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
|
||
|
|
}
|