Start Windows Services


hello all,

newbie here.

i trying write powershell script start number of windows services , notify me status of services.

here steps , descriptions:

1) start multiple windows services (service1, service2, service3, service4)

case 1) if start , enter "running" status, notify me via email status of above services in format:
service1 - running
service2 - running
service3 - running
service4 - running

case2 ) if or of services fail start or throw errors, notify me via email status/errors of above services in format:
service1 - running
service2 - error (whatever error powershell gets)
service3 - error
service4 - stopped

==================

i can status of each of service doing:

get-service -name "service1","service2","service3","service4"

which return:
status,name,displayname
stopped,service1,service1
stopped,service2,service2
running,service3,service3
running,service3,service3

i can start services doing:

start-service -name "service1","service2","service3","service4",

here factors stuck on:
1) these services can started simultaneously, they can take time start.
2) if service fails start first time, try start second time
3) if fails start second time, store error variable , email me status and/or error messages during start.

i hope explains trying accomplish.

your appreciated!


1) start-sleep allow processing wait bit, status of
service not  "running" or "stopped" believe other 2
starting , stopping..
2) loops, while/for/foreach
3) if statements
 
this little complex , done in many different ways
use of loops , if statements need
 
here hint
 
select -expand property
 
will values in property...
 
while((get-service -name $services | select -expand status) -contains
"starting")
{
   sleep 1
}
 
that loop until none of services have status of "starting",
you'll need double check because forget actual status of
a starting service is
 
try see can come , we'll there
 
 

justin rich
http://jrich523.wordpress.com
powershell v3 guide (technet)
please remember mark replies answers if , unmark them if provide no help.


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

some help on Event 540

WMI Repository 4GB limit - Win 2003 Ent Question

Event ID 1302 (error 1307) DFS replication service encountered an error while writing to the debug log file