header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Server downtime report
Last Post 10 Mar 2010 10:39 PM by Pra4ash. 4 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Pra4ashUser is Offline
New Member
New Member
Posts:10
Avatar

--
10 Mar 2010 01:32 AM

    greetings,
    I'm trying to work on a script that calculates the downtime of a server for a given month of the year.
    As i'm a newbie to powershell, it would be great if someone shares their knowledge.

    The following will deduct 6005 and subtract with 6006. (clean shutdown).. also i'm also thinking of adding 6008 (dirty shutdown). The issue with this script is that if there's more than one shutdown, it gives me negative value.

    *Document - attached.

    Thank you.

    Get-QADComputer -ComputerRole 'dc' -Service 'rootdc' -UseGlobalCatalog | Foreach-Object{ $myserver = $_.name $events = Get-WmiObject Win32_NTLogEvent -ComputerName $myserver -Filter "LogFile='system' AND (EventCode=6005 OR EventCode=6006)" | Where-Object {$_.ConvertToDateTime($_.TimeWritten).Month -eq 2 -and $_.ConvertToDateTime($_.TimeWritten).year -eq 2010} if ($events | where-object {$_.eventcode -eq 6005}) { $up = $events | where {$_.EventCode -eq 6005} | sort -desc {$_.ConvertToDateTime($_.TimeWritten)} | select -first 1 $down = $events | where {$_.EventCode -eq 6006} | sort -desc {$_.ConvertToDateTime($_.TimeWritten)} | select -first 1 $dom = get-wmiobject -class "Win32_computersystem" -computername $myserver if($up -AND $down) { $downtime = $up.ConvertToDateTime($up.TimeWritten) - $down.ConvertToDateTime($down.TimeWritten) $totalminutes = [math]::Round([decimal]$downtime.TotalMinutes,0) $dhms = "{0}d {1}h {2}m {3}s" -f $downtime.Days,$downtime.Hours,$downtime.Minutes,$downtime.Seconds $dt = @{Name="Downtime";Expression={$dhms}} $domain = @{Name="Domain";Expression={$dom.domain}} $totalmin = @{Name="Total Minutes";Expression={$totalminutes}} $Name = @{Name="Name";Expression={$dom.name}} $_ | select $Name,$Domain,$dt,$totalmin } } else { $dom = get-wmiobject -class "Win32_computersystem" -computername $myserver $totalminutes = "0" $dhms = "0" $dt = @{Name="Downtime";Expression={$dhms}} $domain = @{Name="Domain";Expression={$dom.domain}} $totalmin = @{Name="Total Minutes";Expression={$totalminutes}} $Name = @{Name="Name";Expression={$dom.name}} $_ | select $Name,$Domain,$dt,$totalmin } } | export-csv down.csv -notypeinformation

    script.txt

    PoSherLifeUser is Offline
    Basic Member
    Basic Member
    Posts:364
    Avatar

    --
    10 Mar 2010 09:10 AM
    I would actually not re-create something that already works. Check out uptime.exe (http://support.microsoft.com/kb/232243)


    When at first you don't succeed Step-Into

    http://theposherlife.blogspot.com
    http://www.jandctravels.com

    Pra4ashUser is Offline
    New Member
    New Member
    Posts:10
    Avatar

    --
    10 Mar 2010 06:02 PM
    Thanks for your reply.
    I've tried out the possibilty of uptime.exe, it works pretty well, except that there's no way to specify a time frame. For instance, if i need the uptime for the month of Feb 2010, it doesn't have such switch.

    Prakash.


    PoSherLifeUser is Offline
    Basic Member
    Basic Member
    Posts:364
    Avatar

    --
    10 Mar 2010 09:47 PM
    You would have to make calculations using the following switches:

    " /d: Only calculate for events after mm/dd/yyyy.
    /p: Only calculate for events in the previous n days."

    So, for Feb you could pull all info from /d: 02/01/2010 and subtract the results from /d: 03/01/2010

    For the running of uptime.exe and the calculations PoSh could be used, definately.


    When at first you don't succeed Step-Into

    http://theposherlife.blogspot.com
    http://www.jandctravels.com

    Pra4ashUser is Offline
    New Member
    New Member
    Posts:10
    Avatar

    --
    10 Mar 2010 10:39 PM
    superb!
    thank you sir.


    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