Timezone Information

While looking at the information available on time via WMI I came across the Win32_TimeZone class

PS> Get-WmiObject -Class Win32_TimeZone | Format-List

Bias      : 0
SettingID :
Caption   : (GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London

Caption is the important piece of information as it gives the time zone name.  As usual get-member can be used to discover further information

Get-WmiObject -Class Win32_TimeZone | Get-Member

There are two set of properties relating to standard and daylight saving time respectively

PS> Get-WmiObject -Class Win32_TimeZone | Select Standard*

StandardBias        : 0
StandardDay         : 5
StandardDayOfWeek   : 0
StandardHour        : 2
StandardMillisecond : 0
StandardMinute      : 0
StandardMonth       : 10
StandardName        : GMT Standard Time
StandardSecond      : 0
StandardYear        : 0

PS> Get-WmiObject -Class Win32_TimeZone | Select Daylight*

DaylightBias        : -60
DaylightDay         : 5
DaylightDayOfWeek   : 0
DaylightHour        : 1
DaylightMillisecond : 0
DaylightMinute      : 0
DaylightMonth       : 3
DaylightName        : GMT Daylight Time
DaylightSecond      : 0
DaylightYear        : 0

So how do we check if we are in daylight saving time?  Unfortunately I couldn’t see a simple property that gave this information so try this

$tz = Get-WmiObject -Class Win32_TimeZone
$d = get-date

$daylton = get-date -month $tz.daylightmonth -day $tz.daylightday -hour $tz.daylighthour -minute $tz.daylightminute -second $tz.daylightsecond
$stndon = get-date -month $tz.standardmonth -day $tz.standardday -hour $tz.standardhour -minute $tz.standardminute -second $tz.standardsecond

if (($d -ge $daylton) -and ($d -le $stndon)){Write-Host "Daylight Saving Time"} else {Write-Host "Standard Time"}

Further information about Win32_Timezone can be found here



Technorati Tags: , ,

This entry was posted in PowerShell and WMI. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s