Solved

Need to start the services

Posted on 2013-11-30
3
271 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
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 24

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 500 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
A brief introduction to what I consider to be the best editor for PowerShell.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

832 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