Quantcast
Viewing all articles
Browse latest Browse all 20598

monitor process state/count on more than 1 server

I am trying to setup some process monitoring where we want the script to return the number of servers its running on as the statistic and the server name as part of the message. I thought this would've been quite simple.

 

so i started with

 

$ErrorActionPreference = 'SilentlyContinue';

 

$proc = $args[0];

 

$s1 = Get-Process -ComputerName <servername1> -Name $proc;

$s2 = Get-Process -ComputerName <servername2> -Name $proc;

 

if($s1 -and !$s2){

  write-host "Statistic: 1";

  Write-Host "Message: $proc is running only on s1";

  Exit(1);}

elseif(!$s1 -and $s2){

  write-host "Statistic: 1";

  Write-Host "Message.: $proc is running only on s2";

  Exit(1);}

elseif(!$s2 -and !$s1 ){

  write-host "Statistic: 0";

  Write-Host "Message: $proc is not running on either S1 or s2";

  Exit(1);}

elseif($s2 -and $s1 ){

  write-host "Statistic: 2";

  Write-Host "Message: $proc is running on both s1 and s2";

  Exit(0);}

 

when i click on get script output all i get is "Get Output Failed" and the text from these write-hosts

  write-host "Statistic: 0";

  Write-Host "Message.Process: $proc is not running on either S1 or s2";

 

I have confirmed winrm is setup correctly, SAM is running from a win2k8r2 box to other win 2k8r2 boxes

i can run the get-process commands directly from powershell as a user or administrator and get the information i was expecting.

 

I have tried get-wmiobject, get-process, and both within invoke-command. i have tried using the server IP addresses. All fail.

 

If i substitute S1 for ${IP} it brings back the data for the server you select to run against, but i need to compare how many processes are running on s1 and s2, to provide valuable feedback.

 

i have had a good scour through the thwack, but couldn't find anything that has been able to get my scripts working. Any help is greatly appreciated.


Viewing all articles
Browse latest Browse all 20598

Trending Articles