Check uptime servers (in this case Citrix servers which reboot every day)

Post date: Mar 02, 2011 8:14:51 AM

At my current job we're running 16 Citrix servers on 8 blades running Citrix-XenServer.

They're supposed to boot everyday so a fresh image is loaded on a daily base.

However sometimes sometimes one or two of the servers are not booted, hanging in shutting down.

This causes people not being abled to logon with an ica session.

To check wether a server has booted i created a little script to check upon the uptime.

If the number of days is not 0 (zero) a message is being sent.

cls

$computerlist = "c:\scripts\inventaris\citrix_servers.txt"

$computers = Get-Content $computerlist

$body = "Citrix Server(s) not booted this morning:"

foreach ($computer in $computers)

{

$wmi = gwmi -ComputerName $computer -Query "SELECT LastBootUpTime FROM Win32_OperatingSystem"

$now = Get-Date

$boottime = $wmi.ConvertToDateTime($wmi.LastBootUpTime)

$uptime = $now - $boottime

$d =$uptime.days

$h =$uptime.hours

$m =$uptime.Minutes

$s = $uptime.Seconds

$Info = "$d Days $h Hours $m Min $s Sec"

if ($d -gt "0"){

$body = $body + "`r`n $computer uptime: $info"

}

}

$emailFrom = "Citrix_Uptime@domain.local"

$emailTo = "helpdesk@domain.local"

$subject = "Server uptime Citrix)"

$smtpServer = "mail01"

$smtp = new-object Net.Mail.SmtpClient($smtpServer)

$smtp.Send($emailFrom, $emailTo, $subject, $body)