Windows uptime should be a fairly straightforward thing to determine.
Ask Windows when it last booted, subtract that timestamp from the current time, and call it a day.
Easy, right?
Between Fast Startup, hibernation, clock adjustments, and the occasional virtualization shenanigans, answering the deceptively simple question of “When was this computer last rebooted?” can be more obnoxious than one might expect.
Grab your watches and jump into the DeLorean: we need to fix the timeline.
The Script
What It Does
This PowerShell script collects and reconciles Windows uptime information from three sources, identifies how the system most recently booted, and attempts to establish when the endpoint last completed a genuine cold boot.
It returns twelve pieces of information:
| Column | Description |
|---|---|
| UptimeSeconds | Selected uptime in seconds |
| UptimeDays | Uptime expressed in days |
| UptimeBucket | Sortable uptime classification |
| BootTimeUTC | Calculated boot timestamp in UTC |
| BootTimeLocal | Calculated boot timestamp in local time |
| BootType | Cold, FastStartup, ResumeFromHibernate, or Unknown |
| LastColdBootUTC | Most recent identified cold boot |
| DaysSinceColdBoot | Days elapsed since that cold boot |
| UptimeSource | Source selected for uptime |
| SourceDeltaSeconds | Largest discrepancy between available sources |
| ClockAnomaly | Whether source disagreement exceeds the configured tolerance |
| SensorVersion | Version of the sensor |
How It Works
1. Why Ask One Source When You Can Have Three for Thrice the Price
Windows exposes uptime information through several mechanisms.
Of course, those sources do not always agree.
The script collects information from three sources, prioritizing them in the following order:
Environment.TickCount64
A kernel-maintained millisecond counter that isn’t directly affected by wall-clock adjustments.
This is our preferred source because changing the system clock doesn’t change the underlying tick counter. These are the good kinds of ticks; certainly not a nervous tick, although troubleshooting Windows uptime may have given me one in the past.
PerfOS SystemUpTime
Retrieved through Win32_PerfFormattedData_PerfOS_System.
Another tick-derived uptime measurement, useful as a fallback when TickCount64 isn’t available.
Win32_OperatingSystem.LastBootUpTime
The familiar WMI property that most administrators have used at some point.
Perfectly useful under normal circumstances, but calculating elapsed uptime from a timestamp makes the result susceptible to discrepancies caused by changes in the system clock.
Here’s the selection logic:
if ($null -ne $tickUptime) {
$uptimeSeconds = $tickUptime
$uptimeSource = 'TickCount64'
} elseif ($null -ne $perfUptime) {
$uptimeSeconds = $perfUptime
$uptimeSource = 'PerfOS_SystemUpTime'
} elseif ($null -ne $wmiUptime -and $wmiUptime -gt 0) {
$uptimeSeconds = $wmiUptime
$uptimeSource = 'Win32_OperatingSystem'
}
It’s worth noting that TickCount64 and PerfOS are related measurements rather than completely independent clocks.
We’re looking for useful corroboration and differences in failure behavior rather than pretending that Windows has three entirely separate stopwatches tucked away somewhere.
2. Reconciling the Timelines
The script calculates the widest disagreement between available sources and compares that value against a configurable tolerance.
$SKEW_TOLERANCE = 300
Five minutes.
If the widest disagreement exceeds that threshold, ClockAnomaly returns True.
Why might the sources disagree?
- System clock adjustments or time synchronization corrections
- Virtual machine restores or unusual virtualization behavior
- Inconsistent instrumentation or stale timestamps
- Other conditions affecting the reliability of reported uptime
An anomaly doesn’t necessarily mean the endpoint is unhealthy.
It means the measurements disagree enough that blindly trusting one of them would be questionable.
Trust but verify, y’all.

3. Determine How Windows Actually Booted
I loathe complexity for complexity’s sake but it is sometimes unavoidable. This is one of those times.
Shut Down and Restart are not necessarily equivalent operations in modern Windows.
With Fast Startup enabled, Windows can preserve the kernel session and drivers through a shutdown rather than starting everything fresh the next time the system powers on.
That distinction can be especially important when you’re trying to determine whether a machine has actually completed a full restart following patching or driver changes. It’s also quite important for implementing maintenance routines like weekly reboots.
Luckily, Windows records useful information about these transitions.
The script queries the System event log:
$bootEvents = Get-WinEvent -FilterHashtable @{
LogName = 'System'
ProviderName = 'Microsoft-Windows-Kernel-Boot'
Id = 27
} -MaxEvents 100 -ErrorAction SilentlyContinue
Event ID 27 exposes a boot-type value that the script interprets as follows:
| Value | Boot Type |
|---|---|
| 0 | Cold |
| 1 | FastStartup |
| 2 | ResumeFromHibernate |
The most recent matching event identifies the current boot type. The script then searches backward through the retrieved events for the most recent cold boot.
This gives us two distinct pieces of information:
How did Windows most recently start?
And:
When did Windows last perform a cold boot?
Those questions are related but they are not the same.
4. Calculate Days Since the Last Cold Boot
Once we’ve identified the most recent cold boot event, calculating elapsed time is straightforward.
if ($lastColdBoot -is [datetime]) {
$daysSinceCold = Format-Decimal ($now - $lastColdBoot).TotalDays
}
Why do I care about this value?
An endpoint’s uptime is not sufficient evidence that the machine has completed the kind of restart required to finalize certain servicing operations.
Consider a workstation that regularly shuts down using Fast Startup.
From the user’s perspective, the machine has been turned off and back on repeatedly. From the kernel’s perspective, some of that state may have been preserved.
Windows doesn’t particularly care whether that distinction makes your patch compliance reporting more complicated.
I do. Probably more than is reasonable. I want all my ticks in order.
One caveat: the script examines the 100 most recent matching boot events. If the last cold boot predates the retained events, it may not be possible to establish that timestamp.
In those cases, missing information remains missing information.
5. Build Output That Tanium Can Actually Use
Like my earlier Windows Event Log sensor, this script is designed to return structured results that Tanium can split into multiple columns.
The output uses a tilde delimiter:
UptimeSeconds~UptimeDays~UptimeBucket~BootTimeUTC~BootTimeLocal~BootType~LastColdBootUTC~DaysSinceColdBoot~UptimeSource~SourceDeltaSeconds~ClockAnomaly~SensorVersion
The script also places uptime values into sortable categories:
| Bucket | Uptime |
|---|---|
| 1 | Under 1 Day |
| 2 | 1–7 Days |
| 3 | 7–14 Days |
| 4 | 14–30 Days |
| 5 | 30–90 Days |
| 6 | Over 90 Days |
These classifications make it much easier to build meaningful reports, dashboards, and endpoint groups.
One other detail worth mentioning: the sensor always attempts to return a populated row, even when it cannot determine uptime.
Unavailable fields are represented by None, and the source is identified as Unavailable.
This avoids an annoying ambiguity: distinguishing between an endpoint that returned an incomplete measurement and one that didn’t return a sensor result at all.
A little defensive programming goes a long way when you’re working at scale.
The Sensor
Details
Suggested Name: Windows Uptime Details
Description: Reports reconciled Windows uptime, boot type, last cold boot, and discrepancies between uptime sources.
Settings
| Setting | Value |
|---|---|
| Category | Operating System |
| Result Type | Text |
| Split into multiple columns | Checked |
| Use Delimiter | ~ |
| Parameters | None |
Configure the twelve output columns in the order documented above.
The script is designed for PowerShell 5.1 and the 32-bit SYSTEM context commonly used by Tanium sensors.
It also handles environments where TickCount64 isn’t available, falling back to PerfOS or WMI rather than immediately failing.



Usage Examples
Patch Management: Who Actually Rebooted?
One of the more frustrating conversations in endpoint management goes something like this:
Administrator: “Your computer needs to be restarted.”
User: “I shut it down every night!”
Administrator: “That’s…not necessarily the same thing.”
With this sensor, we can compare reported uptime, boot type, and time since the last cold boot.
For example, we can investigate endpoints that have recently started through Fast Startup but haven’t recorded a cold boot in several weeks.
That doesn’t prove a particular update is pending or noncompliant, but it gives us useful context when evaluating devices that aren’t completing expected servicing operations.
Combine it with Tanium Patch or other reboot-state information and the investigation becomes considerably more useful.
Reboot Hygiene: Find the Long Runners
The UptimeBucket and DaysSinceColdBoot columns make it easy to identify endpoints that haven’t undergone a genuine cold boot in an unusually long time.
Particularly useful when investigating:
- Workstations routinely avoiding full restarts
- Systems with recurring maintenance issues
- Devices requiring closer examination after patching
- Endpoints whose reboot history doesn’t match expectations
There’s nothing inherently wrong with an endpoint having a long uptime.
There is something wrong with treating uptime as a substitute for understanding its servicing state.
Investigating Suspicious Uptime
Suppose an endpoint’s uptime measurements disagree by several hours.
Which one do you trust?
The script identifies the preferred available uptime source and reports the discrepancy through SourceDeltaSeconds and ClockAnomaly.
Instead of quietly accepting whichever timestamp happens to be convenient, we have a way to identify devices worth investigating.
Useful for environments with virtual machines, frequent clock corrections, or other conditions that can make wall-clock-derived measurements unreliable.

Wrapping Up
One sensor. Three uptime sources. A perfect timeline.
Keep building, friends.

Brent M. Henderson
Build Break Automate LLC
https://buildbreakautomate.com
https://www.linkedin.com/in/brentmhenderson/
Disclaimer: Any code made available on this site is free to use at your own discretion but it is provided without any explicit or implied guarantees of support, reliability, or functionality. I accept no responsibility in the event that the code, in its original form or any derivative versions thereafter, malfunctions or causes problems . Anything from this site that you decide to work with should be tested thoroughly in development environments in collaboration with your Technical Account Manager (TAM) until such time that you, the responsible party, decides that you are satisfied with its outcomes.