Skip to content
Posts Feb 2, 2023 2 min read

Mastering Time with Shell and PowerShell

A comprehensive guide to Windows time management using shell and PowerShell commands, covering system uptime, boot times, time synchronization, and timezone configuration.

Mastering Time with Shell and PowerShell

Explore an array of shell and PowerShell commands focused on time management, including last boot-up time, system boot time, and time zone adjustments.

DATE

Display the current date using the DATE command:

DATE /T

wmic

LastBootUpTime

Retrieve the last boot-up time using Windows Management Instrumentation Command-line (wmic):

wmic path Win32_OperatingSystem get LastBootUpTime

SystemUpTime

Determine system uptime, showing the duration since the last boot-up:

wmic path Win32_PerfFormattedData_PerfOS_System get SystemUpTime

systeminfo

System Boot Time

Obtain the system boot time using the systeminfo command in conjunction with find:

systeminfo | find "System Boot Time"

w32tm

The w32tm command-line tool is used for diagnosing and configuring the Windows Time Service.

configuration

Check the current configuration:

w32tm /query /configuration

Register and Unregister

Register or unregister the Windows Time Service:

w32tm /unregister
w32tm /register

resync

Resynchronize the system clock with the configured time source:

w32tm /resync

query source

Display the current time source and related information:

w32tm /query /source

Win32_OperatingSystem

LastBootUpTime

Calculate the time elapsed since the last boot-up in PowerShell by subtracting the LastBootUpTime from the current date:

(get-date) - (gcim Win32_OperatingSystem).LastBootUpTime

Alternatively, execute the same command within a shell environment:

powershell.exe -c "(get-date) - (gcim Win32_OperatingSystem).LastBootUpTime"

TIME

Obtain the current system time using the TIME command with the /T flag:

TIME /T

tzutil

Display the current time zone:

Show the current time zone:

tzutil /g

Change time zone

Change the system time zone using the tzutil command by providing the desired time zone as an argument after the /s flag. For example, set the time zone to Eastern Standard Time:

tzutil /s "Eastern Standard Time"

Connected Reading

Related entries

Chosen from shared tags, categories, and nearby section context.

Discovery Layer

Connected Memory

A focused relationship view around this entry, using shared categories and tags.

Categories 0
Tags 0
Posts 0