Jump to content
Software FX Community

Uptime formating


murray

Recommended Posts

Hi, I've figured out how to get uptime in seconds but since it's kind of hard to figure out how long the system has been up over 600sec i would like to format it some.

The commandline i used is:

Get-WmiObject -class Win32_PerfFormattedData_PerfOS_System | Out-Gauge -value {$_.systemuptime/60/60/24} -type digital -refresh 0:0:1 -valueformat "##"

 

That's a line for date, but i would like to add more... like YY-MM-DD HH:MM:SS or something like that.. but i just can't figure out a way to do it.

Thanks! 

Link to comment
Share on other sites

You might be able to combine some of these, but you'll want to put all of these commands in a ps1 script, and pipe it to out-gauge:

$time=Get-WmiObject -class Win32_PerfFormattedData_PerfOS_System|%{$_.systemuptime}[datetime]::now.addseconds(-$time).tostring("yy-MM-dd HH:MM:ss")

(I don't get why you'd want to do a refresh when the start time isn't actually going to change.)

The last line above uses .NET to format.  The 2 lines above could be combined into one, but I find the above easier to read.

Link to comment
Share on other sites

Yes, I just solved it with a simular script. I searched the forum for some help and stumbled over (i think it was you) someones reply that you can't refresh a function but a script. Although i didn't do my script with a [datetime]-string... just echoed a normal string and presented it in out-gauge..

 But i think I'm going to use you're code since my code do only count 30 days a month and 12*30 days a year.

 

*EDIT* Just tested your lines and realized that thouse would show the uptime ;). What we need to do is extract the current time and subtract the bootuptime! I'll be back with an edit in a few minutes! :) *EDIT*

 

 

Thank you alot! 

Link to comment
Share on other sites

Boy was this harder than I thought it was going to be.  If I understood, you wanted something to display the uptime in a format like DD:HH:MM:SS.

Well I made my first gadget to display that information. I've attached the pgf file.

Jeffery Hicks

SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.comVBScript & Windows PowerShell Training - www.ScriptingTraining.com/classes.aspWindows PowerShell? - www.SAPIENPress.com/powershell.aspblog: http://blog.SAPIEN.comblog: http://jdhitsolutions.blogspot.com 

Link to comment
Share on other sites

I updated my script to create objects.  Now when run in PowerShell it gives pretty good information.

#Get-Uptime.ps1 

[int]$secup=(Get-WmiObject -class Win32_PerfFormattedData_PerfOS_System).SystemUptime[int]$days=([system.math]::Truncate($secup/86400))[int]$Hours=($secup/3600)%24[int]$Mins=($secup/60)%60[int]$secs=$secup%60#create new object to hold values$obj = New-Object System.ObjectAdd-Member -inputobject $obj -membertype NoteProperty -Name Days -value $daysAdd-Member -inputobject $obj -membertype NoteProperty -Name Hours -value $HoursAdd-Member -inputobject $obj -membertype NoteProperty -Name Minutes -value $MinsAdd-Member -inputobject $obj -membertype NoteProperty -Name Seconds -value $secsWrite-Output $obj

 What I'm not having luck doing is passing it to Out-gauge so that the format is DD:HH:MM:SS.

 Jeffery HicksSAPIEN Technologies - Scripting, Simplified. www.SAPIEN.comVBScript & Windows PowerShell Training - www.ScriptingTraining.com/classes.aspWindows PowerShell? - www.SAPIENPress.com/powershell.aspblog: http://blog.SAPIEN.comblog: http://jdhitsolutions.blogspot.com

 

Link to comment
Share on other sites

Found the solution to MY problem ;)..

 

You got it right, i wanted the uptime..

This is how i did it;

 $time=Get-WmiObject -class Win32_OperatingSystem$t=$time.ConvertToDateTime($time.Lastbootuptime)[TimeSpan]$uptime=New-TimeSpan $t $(get-date)"$($uptime.days)d $($uptime.hours)h $($uptime.minutes)m $($uptime.seconds)S" 

 

Saved this to uptime.ps1 and then ran; .\uptime.ps1 | out-gauge -type digital -refresh 0:0:1 -float

 

Works just fine :-) thanks to both of you guys! 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...