How to auto-start Windows services

how-to-auto-start-Windows-services

#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

Add Arguments: -File S:\Tools\Check-Services.ps1

Related posts

IIS Redirect HTTP to HTTPS

How to auto connnect Open VPN in Windows

1 comment

Vaishnavi Mutkure June 19, 2023 - 12:04 pm
Thanks for the information. I found it useful.
Add Comment