Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - stopping and starting service

Reply
 
Old 10-18-2007   #1 (permalink)
maquinaloca


 
 

stopping and starting service

I am new to powershell and I was wondering if there is a way I can use
powershell to notify me when a particular service on a server has stopped.

My System SpecsSystem Spec
Old 10-18-2007   #2 (permalink)
Brandon Shell [MVP]


 
 

Re: stopping and starting service

The short answer is yes, but to be honest it is not the right tool for the
that job.

Long Answer, If you want to monitor Process,Mem,Service or pretty much anything
you want a persistent application running that goes off in timed intervals.
In this case a Service is really a better option.

If you want to use Powershel then something like this

while($true)
{
if((Get-WmiObject Win32_service | where{$_.name -match $service}).State
-ne "Running")
{
#Do notification of choice
}
}


Brandon Shell
---------------
Blog: http://www.bsonposh.com/
PSH Scripts Project: www.codeplex.com/psobject

m> I am new to powershell and I was wondering if there is a way I can
m> use powershell to notify me when a particular service on a server has
m> stopped.
m>


My System SpecsSystem Spec
Old 10-18-2007   #3 (permalink)
Brandon Shell [MVP]


 
 

Re: stopping and starting service

Marco pointed out that I forgot a sleep statement Without this would loop
pretty fast
while($true)
{
if((Get-WmiObject Win32_service | where{$_.name -match $service}).State
-ne "Running")
{
#Do notification of choice
}
start-sleep 300 # 5 Min
}

Brandon Shell
---------------
Blog: http://www.bsonposh.com/
PSH Scripts Project: www.codeplex.com/psobject

BS> The short answer is yes, but to be honest it is not the right tool
BS> for the that job.
BS>
BS> Long Answer, If you want to monitor Process,Mem,Service or pretty
BS> much anything you want a persistent application running that goes
BS> off in timed intervals. In this case a Service is really a better
BS> option.
BS>
BS> If you want to use Powershel then something like this
BS>
BS> while($true)
BS> {
BS> if((Get-WmiObject Win32_service | where{$_.name -match
BS> $service}).State
BS> -ne "Running")
BS> {
BS> #Do notification of choice
BS> }
BS> }
BS> Brandon Shell
BS> ---------------
BS> Blog: http://www.bsonposh.com/
BS> PSH Scripts Project: www.codeplex.com/psobject
m>> I am new to powershell and I was wondering if there is a way I can
m>> use powershell to notify me when a particular service on a server
m>> has stopped.
m>>


My System SpecsSystem Spec
Old 10-18-2007   #4 (permalink)
Marco Shaw [MVP]


 
 

Re: stopping and starting service

Brandon Shell [MVP] wrote:
Quote:

> The short answer is yes, but to be honest it is not the right tool for
> the that job.
>
> Long Answer, If you want to monitor Process,Mem,Service or pretty much
> anything you want a persistent application running that goes off in
> timed intervals. In this case a Service is really a better option.
>
> If you want to use Powershel then something like this
>
> while($true)
> {
> if((Get-WmiObject Win32_service | where{$_.name -match
> $service}).State -ne "Running")
> {
> #Do notification of choice
> }
> }
And a quick and dirty notification could be via email:

http://mow001.blogspot.com/2005/11/s...-from-msh.html

"Monad" was the original "codename" for PowerShell. Some things will
still work as is with the current PowerShell version.

You can also set up a balloon tip:
http://blog.sapien.com/current/2007/...owershell.html

Marco


--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 10-18-2007   #5 (permalink)
Rob Campbell


 
 

RE: stopping and starting service

If it's a 2003 server, you should be able to use a Powershell script to send
you an email notification, and the options on the services Recovery tab to
invoke the script if the service fails.

"maquinaloca" wrote:
Quote:

> I am new to powershell and I was wondering if there is a way I can use
> powershell to notify me when a particular service on a server has stopped.
My System SpecsSystem Spec
Old 10-19-2007   #6 (permalink)
Herb Martin


 
 

Re: stopping and starting service


"Rob Campbell" <RobCampbell@xxxxxx> wrote in message
news:E83C1770-07DE-4FAD-8698-2663D5D42081@xxxxxx
Quote:

> If it's a 2003 server, you should be able to use a Powershell script to
> send
> you an email notification, and the options on the services Recovery tab to
> invoke the script if the service fails.
>
> "maquinaloca" wrote:
>
Quote:

>> I am new to powershell and I was wondering if there is a way I can use
>> powershell to notify me when a particular service on a server has
>> stopped.
This is the right way to "think" about this. Use the Service options OR an
EventTrigger to start a program (custom, powershell, etc).

Writting a (new) service would likely be overkill for this, and Powershell
is
just one of the choices for responding to such events.


--
Herb Martin, MCSE, MVP
http://www.LearnQuick.Com (phone on web site)

If you use LinkedIn then tell me where you know me from when linking:

http://www.linkedin.com/in/herbmartin


My System SpecsSystem Spec
Old 10-19-2007   #7 (permalink)
Brandon Shell [MVP]


 
 

Re: stopping and starting service

I agree... this is a great idea. Only caveat would be all servers need
powershell installed.

"Herb Martin" <news@xxxxxx> wrote in message
news:%2312OxbpEIHA.4400@xxxxxx
Quote:

>
> "Rob Campbell" <RobCampbell@xxxxxx> wrote in message
> news:E83C1770-07DE-4FAD-8698-2663D5D42081@xxxxxx
Quote:

>> If it's a 2003 server, you should be able to use a Powershell script to
>> send
>> you an email notification, and the options on the services Recovery tab
>> to
>> invoke the script if the service fails.
>>
>> "maquinaloca" wrote:
>>
Quote:

>>> I am new to powershell and I was wondering if there is a way I can use
>>> powershell to notify me when a particular service on a server has
>>> stopped.
>
> This is the right way to "think" about this. Use the Service options OR
> an
> EventTrigger to start a program (custom, powershell, etc).
>
> Writting a (new) service would likely be overkill for this, and Powershell
> is
> just one of the choices for responding to such events.
>
>
> --
> Herb Martin, MCSE, MVP
> http://www.LearnQuick.Com (phone on web site)
>
> If you use LinkedIn then tell me where you know me from when linking:
>
> http://www.linkedin.com/in/herbmartin
>
>
My System SpecsSystem Spec
Old 10-24-2007   #8 (permalink)
Herb Martin


 
 

Re: stopping and starting service


"Brandon Shell [MVP]" <a_bshell@xxxxxx> wrote in message
news:BC656C20-24BD-4C3E-982A-7E661DFB1986@xxxxxx
Quote:

>I agree... this is a great idea. Only caveat would be all servers need
>powershell installed.
Right and that is one of the reasons for the poster to understand that
Powershell is only one way to respond (and perhaps not the best one
for eveyrone.)

Simple batch or even a custom program might be preferable since
EventTriggers can call any of these when the event occurs.


--
Herb Martin, MCSE, MVP
http://www.LearnQuick.Com (phone on web site)

If you use LinkedIn then tell me where you know me from when linking:

http://www.linkedin.com/in/herbmartin

Quote:

> "Herb Martin" <news@xxxxxx> wrote in message
> news:%2312OxbpEIHA.4400@xxxxxx
Quote:

>>
>> "Rob Campbell" <RobCampbell@xxxxxx> wrote in message
>> news:E83C1770-07DE-4FAD-8698-2663D5D42081@xxxxxx
Quote:

>>> If it's a 2003 server, you should be able to use a Powershell script to
>>> send
>>> you an email notification, and the options on the services Recovery tab
>>> to
>>> invoke the script if the service fails.
>>>
>>> "maquinaloca" wrote:
>>>
>>>> I am new to powershell and I was wondering if there is a way I can use
>>>> powershell to notify me when a particular service on a server has
>>>> stopped.
>>
>> This is the right way to "think" about this. Use the Service options OR
>> an
>> EventTrigger to start a program (custom, powershell, etc).
>>
>> Writting a (new) service would likely be overkill for this, and
>> Powershell is
>> just one of the choices for responding to such events.
>>
>>
>> --
>> Herb Martin, MCSE, MVP
>> http://www.LearnQuick.Com (phone on web site)
>>
>> If you use LinkedIn then tell me where you know me from when linking:
>>
>> http://www.linkedin.com/in/herbmartin
>>
>>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
On-line Video playback stopping & starting Media Center
Self starting and stopping torrent software Software
Starting & stopping services VB Script
stopping a program from starting up Vista General
Stopping and Starting Audio Service in Vista Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46