7.13. Returning System UptimeFirst, start with a function for converting WMI date formats into DateTime objects: function parsewmidate { param($wmidate) $year = [int]$wmidate.substring(0, 4) $month = [int]$wmidate.substring(4,2) $day = [int]$wmidate.substring(6,2) $hour = [int]$wmidate.substring(8,2) $min = [int]$wmidate.substring(10,2) $sec = [int]$wmidate.substring(12,2) new-object DateTime $year,$month,$day,$hour,$min,$sec } Use the Win32_OperatingSystem WMI class to calculate uptime and time since last rebuild: function uptime { $reboot = parsewmidate $(get-wmiobject Win32_OperatingSystem).LastBootupTime new-timespan $reboot $(get-date) } function sinceRebuild { { $rebuild = parsewmidate $(get-wmiobject Win32_OperatingSystem).InstallDate new-timespan $rebuild $(get-date) } |