header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
A script that checks to see if servers are online
Last Post 22 Apr 2010 01:59 AM by George Howarth. 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
NTD13User is Offline
New Member
New Member
Posts:5
Avatar

--
21 Apr 2010 10:30 AM
    Hello All,

    I have written a small script that checks to see if my servers are online and emails me the results.  The script is shown below.


    add-PSSnapin quest.activeroles.admanagement -ea SilentlyContinue

    $Body = ""
    $Servers = @(Get-QADComputer -ManagedBy ccit | foreach{$_.name} | Sort-Object)
    ForEach($Server In $Servers){
    $PingStatus = Gwmi Win32_PingStatus -Filter "Address = '$Server'" |
    Select-Object StatusCode
    If ($PingStatus.StatusCode -eq 0)
    {$Body = "$Body$($Server) is online and answering pings. `n"}
    Else
    {$Body = "$Body$($Server) IS OFFLINE AND NEEDS TO BE CHECKED IMMEDIATELY. `n"}
    }

    $Mail = New-Object System.Net.Mail.MailMessage( `
      ServerAdmin@test.com, `
      "ndalmolin@test.com", `
      "Server Disk Report", `
      $Body)
     
    $Mail.IsBodyHTML = $True
     
    $Smtp = New-Object System.Net.Mail.SmtpClient("cas-hub01.test.com")
    $Smtp.Send($Mail)

    Here is the body of the email that I receive:
    TS01 is online and answering pings. VM02 IS OFFLINE AND NEEDS TO BE CHECKED IMMEDIATELY. VM03 is online and answering pings. WICHITA is online and answering pings.

    Here are my questions:
    How can I format the body so that each server's status is on its own line?  Example:
    TS01 is online and answering pings.
    VM02 IS OFFLINE AND NEEDS TO BE CHECKED IMMEDIATELY.
    VM03 is online and answering pings.
    WICHITA is online and answering pings.

    Can I make online servers highlighted in green and offline servers highlighted in red?

    As always, any and all help is greatly appreciated.

    Nick
    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    22 Apr 2010 01:59 AM

    Try this:

    Add-PSSnapin Quest.ActiveRoles.ADManagement -ea SilentlyContinue

    $body = New-Object System.Text.StringBuilder
    $servers = @(Get-QADComputer -ManagedBy ccit | ForEach-Object { $_.name } | Sort-Object)
    foreach ($server in $servers)
    {
        $pingStatus = Get-WmiObject Win32_PingStatus -Filter "Address = '$server'" | Select-Object StatusCode
       
        if ($pingStatus.StatusCode -eq 0)
        {
            $body.Append("< font color=`"#00FF00`" >$server is online and answering pings.< /font >< br/ >") | Out-Null
        }
        else
        {
            $body.Append("< font color=`"#FF0000`" >$server IS OFFLINE AND NEEDS TO BE CHECKED IMMEDIATELY.< /font >< br/ >") | Out-Null
        }
    }

    $mail = New-Object System.Net.Mail.MailMessage("ServerAdmin@test.com", "ndalmolin@test.com", "Server Disk Report", $body.ToString())
    $mail.IsBodyHTML = $true
     
    $smtp = New-Object System.Net.Mail.SmtpClient("cas-hub01.test.com")
    $smtp.Send($mail)

    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer