Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Uptime script - comments, critiques?

115 views
Skip to first unread message

Alex K. Angelopoulos at

unread,
Sep 5, 2008, 1:03:40 PM9/5/08
to
I'm working on a generic uptime script that might benefit from having a few
people thump on the ugly bits. Anyone care to try this? The intent is to
allow it to return uptime checks on multiple systems, complete with
essential information such as the boot time and the time of the check. I'm
pretty certain I need to change a couple of items, including adding some
kind of display hinting to the output instead of using the ugly AsPSObject
parameter. BTW, PS 1 compatibility isn't a strict requirement for this; I'm
not up to speed on PS 2 scripting details yet, so there may be some design
changes that are a good idea here.

#Get-Uptime.ps1
Param([string[]]$ComputerName = @("."),
[switch]$AsPSObject)

foreach($computer in $ComputerName){
$os = Get-WmiObject Win32_OperatingSystem `
-ComputerName $computer
$LastBootUpTime = $os.ConvertToDateTime($os.LastBootUpTime)
$LocalDateTime = $os.ConvertToDateTime($os.LocalDateTime)

#Calculate uptime - this is automatically a timespan
$up = $LocalDateTime - $LastBootUpTime

#Create a simple text string representation of the uptime;
# unfortunately only English
# Maybe drop this? It's UNIX-uptime like, but ugly.
$text = "$($os.CSName) up $($up.Days) days, $($up.Hours) hours," +
" $($up.Minutes) minutes, $($up.Seconds) seconds"
# Add bootuptime DateTime value
$up = Add-Member -MemberType NoteProperty `
-Name LastBootUpTime -Value $LastBootUpTime `
-InputObject $up -PassThru |
Add-Member -MemberType NoteProperty `
-Name LocalDateTimestamp -Value $LocalDateTime -PassThru |
Add-Member -MemberType NoteProperty `
-Name ComputerName -Value $os.csname -PassThru |
Add-Member -MemberType NoteProperty `
-Name Text -Value $text -PassThru
if($AsPSObject){$up | Select-Object}else{$up}
}

0 new messages