aalborz
 New Member Posts:56

 |
| 14 May 2008 02:59 PM |
|
Can PS monitor a process on an NT server box? Would it require PS to be installed locally on the box or can it be done remotely (the preferred method)?
If so, I'd like to see how to put together a script, so it monitors a process's status and when it changes, it will send an email notification.
TIA
Alex
|
|
|
|
|
aalborz
 New Member Posts:56

 |
| 14 May 2008 06:02 PM |
|
I got this working myself...well kind of.
I used the Get-WmiObject Win32_Process, instead of the Get-Process command. It works on few NT boxes, but not all. I get an error message about Class not being registered.
Appreciate any help!
Alex
|
|
|
|
|
chris.harrod
 New Member Posts:4

 |
| 14 May 2008 06:15 PM |
|
Hopefully this works.
$service = get-service -ComputerName lfi-fs-EDIT -include Alerter
if ($service.Status -eq "Stopped"){
$emailFrom = "chris.harrod@edit.edit"
$emailTo = "chris.harrod@edit.edit"
$subject = "Service has enetered stop state."
$body = "Service has enetered stop state."
$smtpServer = "LFI-CS-EDIT.EDIT"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
}
|
|
|
|
|
chris.harrod
 New Member Posts:4

 |
| 14 May 2008 06:16 PM |
|
That's just something I threw together really quick. You could set it up as a scheduled task on the server and go from there.
I'm sure there are other ways to accomplish the same task. |
|
|
|
|
halr9000 PowerShell MVP, Site Admin
 Basic Member Posts:334

 |
| 14 May 2008 06:28 PM |
|
If you want something to work at an interactive real-time fashion, then you ought to do that via code executing or triggering locally on the box, that's just good architecture. If you don't mind polling at 5, 10, 60 min intervals, you can do it remotely. If you poll remotely, you could do that by using the Get-WmiObject cmdlet like so: get-wmiobject win32_process -computer |
|
Community Director, PowerShellCommunity.org Co-host, PowerScripting Podcast Author, TechProsaic |
|
|
aalborz
 New Member Posts:56

 |
| 14 May 2008 06:28 PM |
|
Thanks, but I wanted to monitor a process not a service. I'm familiar with doing both using PS.
I just wanted to know if there's anything can be done for a NT box specifically. Like I said in my earlier post, I got it working, but it doesn't work on couple of NT servers. |
|
|
|
|
aalborz
 New Member Posts:56

 |
| 14 May 2008 06:32 PM |
|
halr9000,
That's exactly how I got it working, using two functions: one for email and one for checking whether the process is running. Remotely, it goes through a counter of 4, sleeps for 60 second, and starts again.
It's working ok, but not on couple of NT servers. I'm trying to resolve that part.
Thx
Alex
|
|
|
|
|
halr9000 PowerShell MVP, Site Admin
 Basic Member Posts:334

 |
|
aalborz
 New Member Posts:56

 |
| 14 May 2008 07:21 PM |
|
Yes sir. We've been down that road many times. The application won't run on anything else and it also requires Outlook 98.
We have newer version of it running on W2K & W2K3 boxes, but this one is used for supporting clients old projects, which won't go away any time soon, if ever. |
|
|
|
|
chris.harrod
 New Member Posts:4

 |
| 14 May 2008 07:26 PM |
|
If NT were a sponge it would soak up the internet and its clogged tubes. |
|
|
|
|