Advertisement
kjacobsen

Server Up Time Monitoring

Apr 2nd, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Code Snippet from aperturescience.su
  2. # Parameters
  3. [Parameter(Position=5, Mandatory=$false, HelpMessage="Maximum uptime allowed")]$maxuptime=45,
  4.  
  5.  
  6. # Function to help format the strings
  7.  
  8. function WMIDateStringToDate($Bootup) {
  9.     [System.Management.ManagementDateTimeconverter]::ToDateTime($Bootup)
  10. }
  11.  
  12. # Main Body
  13. $negmax = -$maxuptime
  14.  
  15. $system = Get-WmiObject -class Win32_OperatingSystem
  16.  
  17. $Bootup = $system.LastBootUpTime
  18. $LastBootUpTime = WMIDateStringToDate($Bootup)
  19.  
  20. $now = Get-Date
  21. $Uptime = $now - $LastBootUpTime
  22. $d = $Uptime.Days
  23. $h = $Uptime.Hours
  24. $m = $uptime.Minutes
  25.  
  26. Write-Verbose "System Up for: $($d) days, $($h) hours, $($m) minutes"
  27.  
  28. if ($LastBootUpTime -lt $now.adddays($negmax))
  29. {
  30.     Write-Verbose "System has been up longer than $maxuptime days"
  31. }
  32. else
  33. {
  34.     Write-Verbose "System has not been up longer than $maxuptime days"
  35. }
  36. # Code Snippet from aperturescience.su
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement