Main example
List instances
# All instances of Win32_TimeZone, with the main properties
Get-CimInstance -ClassName Win32_TimeZone |
Select-Object -Property StandardName, Caption, Description, BiasExamples
Filter with WQL
# WQL filter evaluated by the provider: DaylightDayOfWeek = 0 (Sunday)
Get-CimInstance -ClassName Win32_TimeZone -Filter 'DaylightDayOfWeek = 0' |
Select-Object -Property StandardName, Caption, Description, BiasThe filter is evaluated by the WMI provider: less data is transferred than with Where-Object.
Decode numeric values
# Lookup table for DaylightDayOfWeek (values documented by Microsoft)
$daylightDayOfWeekName = @{
0 = 'Sunday'
1 = 'Monday'
2 = 'Tuesday'
3 = 'Wednesday'
4 = 'Thursday'
5 = 'Friday'
6 = 'Saturday'
}
# Lookup table for DaylightMonth (values documented by Microsoft)
$daylightMonthName = @{
1 = 'January'
2 = 'February'
3 = 'March'
4 = 'April'
5 = 'May'
6 = 'June'
7 = 'July'
8 = 'August'
9 = 'September'
10 = 'October'
11 = 'November'
12 = 'December'
}
Get-CimInstance -ClassName Win32_TimeZone |
Select-Object -Property @(
'StandardName'
'Caption'
'Description'
'Bias'
@{ Name = 'DaylightDayOfWeek'; Expression = { $daylightDayOfWeekName[[int]$_.DaylightDayOfWeek] } }
@{ Name = 'DaylightMonth'; Expression = { $daylightMonthName[[int]$_.DaylightMonth] } }
)Query a remote computer (CIM session)
review before running# Name of the remote computer
$computerName = 'SERVER01'
# The CIM session (WSMan by default) can be reused for several queries
$cimSession = New-CimSession -ComputerName $computerName
try {
Get-CimInstance -CimSession $cimSession -ClassName Win32_TimeZone |
Select-Object -Property StandardName, Caption, Description, Bias
} finally {
Remove-CimSession -CimSession $cimSession
}WSMan (WinRM) is used by default. For a host without WinRM, create the session with -SessionOption (New-CimSessionOption -Protocol Dcom). Add -Credential to use another account.
Show the class structure
# Class structure: properties, types and flags (Key, ReadOnly…)
$cimClass = Get-CimClass -ClassName Win32_TimeZone
$cimClass.CimClassProperties |
Select-Object -Property Name, CimType, FlagsProperties
| Name | Type | Access | Description | |||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Bias# | sint32 | read | Current bias for local time translation. The bias is the difference between Coordinated Universal Time (UTC) and local time. All translations between UTC and local time are based on the following formula: UTC = local time - bias. This property is required. Unit: minutes Code | |||||||||||||||||||||||||||||||||||||||
| Caption# | string | read | Short textual description of the current object. Code | |||||||||||||||||||||||||||||||||||||||
| DaylightBias# | sint32 | read | Bias value to be used during local time translations that occur during daylight saving time. This property is ignored if a value for the DaylightDay property is not supplied. The value of this property is added to the Bias property to form the bias used during daylight time. In most time zones, the value of this property is -60. Unit: minutes Code | |||||||||||||||||||||||||||||||||||||||
| DaylightDay# | uint32 | read | DaylightDayOfWeek of the DaylightMonth when the transition from standard time to daylight saving time occurs on this operating system. Example: If the transition day (DaylightDayOfWeek) occurs on a Sunday, then the value "1" indicates the first Sunday of the DaylightMonth, "2" indicates the second Sunday, and so on. The value "5" indicates the last DaylightDayOfWeek in the month. Code | |||||||||||||||||||||||||||||||||||||||
| DaylightDayOfWeek# | uint8 | read | Day of the week when the transition from standard time to daylight saving time occurs on an operating system. Example: 1 Values (7)
Code | |||||||||||||||||||||||||||||||||||||||
| DaylightHour# | uint32 | read | Hour of the day when the transition from standard time to daylight saving time occurs on an operating system. Example: 2 Code | |||||||||||||||||||||||||||||||||||||||
| DaylightMillisecond# | uint32 | read | Millisecond of the DaylightSecond when the transition from standard time to daylight saving time occurs on an operating system. Code | |||||||||||||||||||||||||||||||||||||||
| DaylightMinute# | uint32 | read | Minute of the DaylightHour when the transition from standard time to daylight saving time occurs on an operating system. Example: 59 Code | |||||||||||||||||||||||||||||||||||||||
| DaylightMonth# | uint32 | read | Month when the transition from standard time to daylight saving time occurs on an operating system. Values (12)
Code | |||||||||||||||||||||||||||||||||||||||
| DaylightName# | string | read | Time zone being represented when daylight saving time is in effect. Example: "EDT" (Eastern Daylight Time) Code | |||||||||||||||||||||||||||||||||||||||
| DaylightSecond# | uint32 | read | Second of the DaylightMinute when the transition from standard time to daylight saving time occurs on an operating system. Example: 59 Code | |||||||||||||||||||||||||||||||||||||||
| DaylightYear# | uint32 | read | Year when daylight saving time is in effect. This property is not required. Example: 1997 Code | |||||||||||||||||||||||||||||||||||||||
| Description# | string | read | Textual description of the current object. Code | |||||||||||||||||||||||||||||||||||||||
| SettingID# | string | read | Identifier by which the current object is known. Code | |||||||||||||||||||||||||||||||||||||||
| StandardBias# | uint32 | read | Bias value to use when daylight saving time is not in effect. This property is ignored if a value for StandardDay is not supplied. The value of this property is added to the Bias property to form the bias during standard time. Example: 0 Unit: minutes Code | |||||||||||||||||||||||||||||||||||||||
| StandardDay# | uint32 | read | StandardDayOfWeek of the StandardMonth when the transition from daylight saving time to standard time occurs on an operating system. If the transition day (StandardDayOfWeek) occurs on a Sunday, then the value "1" indicates the first Sunday of the StandardMonth, "2" indicates the second Sunday, and so on. The value "5" indicates the last StandardDayOfWeek in the month. Code | |||||||||||||||||||||||||||||||||||||||
| StandardDayOfWeek# | uint8 | read | Day of the week when the transition from daylight saving time to standard time occurs on an operating system. Values (7)
Code | |||||||||||||||||||||||||||||||||||||||
| StandardHour# | uint32 | read | Hour of the day when the transition from daylight saving time to standard time occurs on an operating system. Example: 11 Code | |||||||||||||||||||||||||||||||||||||||
| StandardMillisecond# | uint32 | read | Millisecond of the StandardSecond when the transition from daylight saving time to standard time occurs on an operating system. Code | |||||||||||||||||||||||||||||||||||||||
| StandardMinute# | uint32 | read | Minute of the StandardDay when the transition from daylight saving time to standard time occurs on an operating system. Example: 59 Code | |||||||||||||||||||||||||||||||||||||||
| StandardMonth# | uint32 | read | Month when the transition from daylight saving time to standard time occurs on an operating system. Values (12)
Code | |||||||||||||||||||||||||||||||||||||||
| StandardName# key | string | read | Name of the time zone being represented when standard time is in effect. Example: "EST" (Eastern Standard Time) Code | |||||||||||||||||||||||||||||||||||||||
| StandardSecond# | uint32 | read | Second of the StandardMinute when the transition from daylight saving time to standard time occurs on an operating system. Example: 59 Code | |||||||||||||||||||||||||||||||||||||||
| StandardYear# | uint32 | read | Year when standard time is in effect. This property is not required. Example: 1997 Code |
Remarks
The Win32_TimeZone class is derived from CIM_Setting.
You cannot use standard date-time formats - such as 10/18/2002 - when writing WMI queries. Instead, you need to convert any dates used in your queries to UTC format. This requires two steps: 1) You must determine the offset (difference in minutes) between your time zone and Greenwich Mean Time, and 2) you must convert 10/18/2002 to a UTC value.
Determining the Offset from Greenwich Mean Time
Admittedly, WMI makes it difficult to work with dates and times; fortunately, WMI at least makes it easy to determine the offset between your time zone and Greenwich Mean Time. The WMI class Win32_TimeZone includes a property - Bias - that returns the GMT offset.
```VB
strComputer = "."
Set objSWbemServices = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colTimeZone = objSWbemServices.ExecQuery _
("SELECT * FROM Win32_TimeZone")
For Each objTimeZone in colTimeZone
Wscript.Echo "Offset: "& objTimeZone.Bias
Next
```
Converting a Date to a UTC Value
After you determine the GMT offset, you must then convert a standard date such as 10/18/2002 to a UTC date. To convert a standard date to a UTC date, you can use VBScript date functions such as Year, Month, and Day to isolate the individual components that make up a UTC date. After you have individual values for these components, you can concatenate them in the same manner as you would any other string value. UTC dates are treated as strings because the GMT offset must be appended to the end. If the date were seen as a number, this value:
20011018113047.000000-480
Would be erroneously treated as a mathematical equation (parentheses added for clarity):
(20011018113047.000000) - (480)
For example, in the date 10/18/2002, the individual components are:
- Year: 2002
- Month: 10
- Day: 18
The script would need to combine these three values, the string "113047.000000" (representing the time, including milliseconds), and the GMT offset to derive a UTC date. For example, (parentheses again added for clarity):
(2002) & (10) & (18) & (113047.000000) & (-480)
Note: You can use the VBScript functions Hour, Minute, and Second to convert the time portion of a UTC date. Thus, a time such as 11:30:47 A.M. would be converted to 113047.
There is one complicating factor. The month must take up positions 5 and 6 in the string; the day must take up positions 7 and 8. This is no problem with month 10 and day 18. But how do you get July 5 (month 7, day 5) to fill up the requisite positions? The answer is to add a leading zero to each value, thus changing the 7 to 07 and the 5 to 05.
To do this, use the VBScript Len function to check the length (number of characters) in the month and the day. If the length is 1 (meaning that there is just one character), add a leading zero. Thus:
```VB
If Len(dtmMonth) = 1 Then
dtmMonth = "0" & dtmMonth
End If
```
Inheritance
Superclass chain
- CIM_Setting
- Win32_TimeZone
Known subclasses
No known subclass.
Requirements
- Namespace
- root/cimv2
- Minimum client
- Windows Vista
- Minimum server
- Windows Server 2008
- Provider
- CIMWin32
- MOF file
- CIMWin32.mof
- DLL
- CIMWin32.dll
Class qualifiers
Dynamic Provider("CIMWin32") UUID("{8502C4EC-5FBB-11D2-AAC1-006008C78BC7}") AMENDMENT
Microsoft source
Descriptions, properties and methods come from the Microsoft documentation (MicrosoftDocs/win32 repository), published under the CC BY 4.0 licence. Formatting and translations are specific to this site; the PowerShell examples are written for it.