Getting system uptime   Leave a comment

Sometimes I miss my Unix system. Actually, that’s not true, sometimes I miss the tools that are available.  For example, I needed to figure out when the system booted.  Thankfully, there are performance counters that can tell me!

PS# cat get-uptime.ps1
$PCounter = "System.Diagnostics.PerformanceCounter"
$counter = new-object $PCounter System,"System Up Time"
$value = $counter.NextValue()
$uptime = [System.TimeSpan]::FromSeconds($counter.NextValue())
"Uptime: $uptime"
"System Boot: " + ((get-date) - $uptime)

Simple!

Advertisements

Posted July 28, 2009 by jtruher3 in PowerShell

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: