Thursday, October 06, 2011

Get Time Zones for your users via PowerShell

We recently released a cmdlet that bulk-inserts holidays in Exchange 2010 (see the Sumatra website or the Sumatra Blog).

A holiday is a simple all day calendaring event in Outlook. Yet simple calendaring events can be tricky! Consider: when your end users work in different time zones! If you force an all day event into one time zones, all users who are not in that time zone will see their holidays span multiple days. Not a happy scenario. What's the solution?

We wrote a script that uses Exchange 2010 "get-mailboxRegionalConfiguration" cmdlet to find the timezones. If used in conjunction with get-mailbox, you can output a file that has the user information plus the timezone. Problem solved!

This script produces a file that outputs PrimarySMTPAddress + TimeZone:
#Define your 'default' timezone (if none is set)
$myDefaultTimezone="Eastern Standard Time"

#Define the output file
$myOutputFile="userlist.txt"

#Define the list of User Accounts to process
$myMailboxList = get-mailbox -Filter {RecipientTypeDetails -eq "UserMailbox"}  select-object Identity,PrimarySMTPAddress

#If file exists, delete the file
$fileExists=test-Path $myOutputFile
if ($fileExists -eq "True"){del $myOutputFile}


#Loop through list and get
foreach ($t in $myMailboxList) {
    $priSMTP=$t.PrimarySMTPAddress
    $xi=get-mailboxRegionalConfiguration -Identity $t.Identity
    if ($xi.TimeZone -eq $Null) {$tt=$myDefaultTimezone} Else {$tt=$xi.TimeZone}
    write-output "$priSMTP $tt" >> $myOutputFile
}

write-output "Done!  see the file $myOutputFile"

You can also download getUserTimezones.zip

If you have another way, please share!

-Russ

No comments: