Skip to content

Instantly share code, notes, and snippets.

@ltao31
Created February 8, 2024 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ltao31/cac25da7a49c072a611838c415970e44 to your computer and use it in GitHub Desktop.
Save ltao31/cac25da7a49c072a611838c415970e44 to your computer and use it in GitHub Desktop.
Gets the last bootup time for a windows system
<#
.SYNOPSIS
Get the system boot time
.DESCRIPTION
This PowerShell script gives the system boot time.
The format is Year,month,day, hour, minutes, seconds, milliseconds, and timezone.
.EXAMPLE
PS> ./GetSystemBoottime
#>
try {
$operatingSystem = Get-WmiObject Win32_OperatingSystem
"$($operatingSystem.LastBootUpTime)"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment