PowerShell With Uptime - Getting Days Only

ben himself's picture

There is a handy and free tool to check your system's uptime called "Uptime".  (Clever, no?)  It can be downloaded at http://uptimeexe.codeplex.com.

While it is very easy to use (just navigate to it in a command window and type "uptime"), it doesn't give much of an option for formatting the output to include only the days.  So, a simple workaround is to use some "replace" commands within PowerShell and only output the number of days.  Here's how:

cd c:\uptime
$server = "SERVER_NAME";
$up = .\uptime.exe $server;
$days = $up -replace "\\\\" + $server + " has been up for: ";
$days = $days -replace " day(.*)$";
$days;

 

Tags: 

Categories: