Home » How to auto-start Windows services

How to auto-start Windows services

by Salman Chawhan
1 comment

#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

You may also like

1 comment

Vaishnavi Mutkure June 19, 2023 - 12:04 pm

Thanks for the information. I found it useful.

Reply

Leave a Comment

9 + 8 =

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
-
00:00
00:00
Update Required Flash plugin
-
00:00
00:00