Solved

Need to start the services

Posted on 2013-11-30
3
268 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This article will help you understand what HashTables are and how to use them in PowerShell.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

7 Experts available now in Live!

Get 1:1 Help Now