47
#start the following Windows services in the specified order:
[Array] $Services = ‘MailService’,’SpamAssassin’,’OpenVPNServiceInteractive’,’Certify.Service’,’Schedule’;
#loop through each service, if its not running, start it
foreach($ServiceName in $Services)
{
$arrService = Get-Service -Name $ServiceName
write-host $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’
}
}
}
Copy above code and make .ps1
ex: CheckService.ps1
How to configure in task Scheduler
Open Task scheduler
Go to Action —> Create Task
You Might Also Like