Recipes by topic

Time zone and UTC offset

Win32_TimeZone describes the configured time zone; Win32_ComputerSystem gives the offset currently in effect and tells whether daylight saving time is active.

$timeZone = Get-CimInstance -ClassName Win32_TimeZone
$computerSystem = Get-CimInstance -ClassName Win32_ComputerSystem

[PSCustomObject]@{
    Caption            = $timeZone.Caption
    StandardName       = $timeZone.StandardName
    DaylightName       = $timeZone.DaylightName
    DaylightInEffect   = $computerSystem.DaylightInEffect
    CurrentOffsetHours = $computerSystem.CurrentTimeZone / 60
}

CurrentTimeZone is expressed in minutes from UTC and accounts for daylight saving time: divided by 60, it gives the offset in hours (1 in winter and 2 in summer for Paris). Bias in Win32_TimeZone is the standard offset with the opposite sign (the number of minutes to add to local time to get UTC): it does not change with daylight saving time.

Variant: remote

Useful to spot a server left on the wrong time zone.

$cimSession = New-CimSession -ComputerName 'SERVER01', 'SERVER02'
try {
    $cimParameters = @{
        CimSession = $cimSession
        ClassName  = 'Win32_TimeZone'
    }
    Get-CimInstance @cimParameters |
        Select-Object -Property PSComputerName, Caption, StandardName
} finally {
    Remove-CimSession -CimSession $cimSession
}

Classes used

← All recipes