Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need to start the services

Posted on 2013-11-30
3
Medium Priority
?
277 Views
Last Modified: 2013-12-30
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
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Expert Comment

by:XGIS
ID: 39687994
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
 
LVL 25

Expert Comment

by:Lionel MM
ID: 39688433
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
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 39690274
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief introduction to what I consider to be the best editor for PowerShell.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question