Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

Need to start the services

I need to restart  5 windows services one by one.
1.if the services doesn't start, it should wait for 30 second and re-try for 3 times.
2. if it's gets started it should go for next services.
3. likewise it should do rest of 5 services
4.finally exit. saying all services started successfully.
5. if any one of services fail then it should write to the log saying particular service failed.
0
VIVEKANANDHAN_PERIASAMY
Asked:
VIVEKANANDHAN_PERIASAMY
1 Solution
 
XGISCommented:
Here is a link to implementation using powershell
Powershell Service examples

To do the same thing with a batch file;
Start  
NET START ServiceName

Stop
NET STOP ServiceName

The Service Properties may then be setup to start other batch files.
This may be an alternate approach to PS
0
 
Lionel MMSmall Business IT ConsultantCommented:
Check out this batch file. Once copied rename it from ee1.txt to ee1.bat then run from a command prompt. I put PAUSEs in place so you can see what it is doing. Once it is working your can get rid of all the pauses. I also made the wait time to be only 5 seconds for testing purposes--again once you are satisfied change the line Timeout /T 5 to Timeout /T 30. Let me know if that works for you. Also once done change the first line Echo on to Echo Off.
ee1.txt
0
 
SubsunCommented:
Try..
$Col = @()
"ServiceA","ServiceB","ServiceC","ServiceD","ServiceE" | % {
 $svc = Get-Service $_
 Restart-Service -InputObject $svc
	Sleep -Seconds 30
	$i = 0
	While($svc.Status -ne 'Running'){
	$i++
	Start-Service -InputObject $svc
	Sleep -Seconds 30
	If ($i -eq 3 -or $svc.Status -eq 'Running'){Break}
	}
	If ($svc.Status -ne 'Running'){
	$Col += $svc
	}
}
If ($Col -eq $null){
Write-Host "All services started successfully"
}Else{
$Col
}

Open in new window

0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now