Solved

Need to start the services

Posted on 2013-11-30
3
269 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:lionelmm
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now