Skip to content

Generates a Time Zone table with current date and time in each Time Zone and exports it to a HTML- and a CSV-file (a Windows PowerShell script).

License

Notifications You must be signed in to change notification settings

auberginehill/get-time-zone-table

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Get-TimeZoneTable.ps1

OS: Windows
Type: A Windows PowerShell script
Language: Windows PowerShell
Description: Get-TimeZoneTable queries the general Time Zone information list from the Windows registry under the "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\" key and stores the found properties (subkeys, of which, in essence, each subkey contains the data of an individual time zone) as an collection of objects. In addition to the Windows registry query Get-TimeZoneTable uses Windows Management Instrumentation (WMI) to retrieve the current Time Zone and other basic computer information. The results are displayed in a pop-up window (Out-GridView), written to a HTML Time Zone Table -file and to a CSV-file. The files are saved to the path defined by a parameter called -Path and -Sort and -Descending parameters toggle, how the results are written to those files.
Homepage: https://github.com/auberginehill/get-time-zone-table
Short URL: http://tinyurl.com/h5z2de6
Version: 1.0
Sources:
Emojis: https://api.github.com/emojis
Josh Free: Exploring Windows Time Zones with System.TimeZoneInfo
Martin Pugh: Get-FolderSizes
CB.: Dynamic parameter accessing default value
PowerTip: Use PowerShell to retrieve the date and time of the given time zone ID
Downloads: For instance Get-TimeZoneTable.ps1. Or everything as a .zip-file.

Screenshot

screenshot

Parameters

πŸ“
  • Parameter -Path

    which has an alias called -ReportPath (so they both act exactly the same way). The -Path parameter specifies where the HTML Time Zone Table and the adjacent CSV-file is to be saved. The default save location is $env:temp, which points to the current temporary file location, which is set in the system. The default -Path save location is defined at line 12 with the $Path variable. If no save location is defined in the command, the files are saved to $env:temp.

    It's not always mandatory to write -Path in the command to invoke the -Path parameter, as is shown in the Examples below, since Get-TimeZoneTable is trying to decipher the inputted commands as good as it is machinely possible within a 50 KB size limit.

    The save location path should be a valid file system path to a directory (a full path name of a directory (i.e. folder path such as C:\Windows)). In case the path name includes space characters, please add quotation marks around the path name. For usage, please see the Examples below and for more information about $env:temp, please see the Notes section below.

  • Parameter -Sort

    Specifies which column is the primary sort column in the HTML Time Zone Table and other outputs. Only one column may be selected in one command as the primary column. If -Sort parameter is not defined, Get-TimeZoneTable will try to sort by Date (Current), Time (Current) and Time Zone Id in an ascending order.

    In the HTML Time Zone Table and other outputs all the headers are sortable (with the commands) and some headers have aliases, too. Valid -Sort values are listed below. Please also see the Examples section for further usage examples.

      Valid -Sort values:

      Value Sort Behavior
      "Time Zone Id" Sort by Time Zone Id
      Name Sort by Time Zone Id
      Id Sort by Time Zone Id
      English Sort by Time Zone Id
      "Date (Current)" Sort by Date (Current)
      Date Sort by Date (Current)
      "Time (Current)" Sort by Time (Current)
      Time Sort by Time (Current)
      Offset Sort by Offset
      Display Sort by Offset
      Value Sort by Offset
      UTC Sort by UTC
      Area Sort by Area
      "Standard Time (in system language)" Sort by Standard Time (in system language)
      "Standard Time" Sort by Standard Time (in system language)
      Standard Sort by Standard Time (in system language)
      Winter Sort by Standard Time (in system language)
      "Daylight Saving Time (in system language)" Sort by Daylight Saving Time (in system language)
      "Daylight Saving Time" Sort by Daylight Saving Time (in system language)
      Daylight Sort by Daylight Saving Time (in system language)
      Summer Sort by Daylight Saving Time (in system language)
      PSDrive Sort by PSDrive
      PSPath Sort by PSPath

  • Parameter -Descending

    A switch to control how directories get sorted in the HTML Time Zone Table and other outputs, when also the -Sort parameter is used. By default Get-TimeZoneTable tries to sort everything in an ascending order. After defining the primary sort column with the -Sort parameter the prevalent ascending sort order may be reversed by adding the -Descending parameter to the command.

Outputs

➑️
  • Generates an HTML Time Zone Table and an adjacent CSV-file in a specified Path ($Path = "$env:temp" at line 12), which is user-settable with the -Path parameter. Displays the prevalent time zone in console. In addition to that...

  • One pop-up window "$results_selection" (Out-GridView) with sortable headers (with a click):
    1. Name Description
      $results_selection Displays the Time Zone Table

  • And also the aforementioned HTML-file "Time Zone Table" and CSV-file at $Path. The HTML-file "Time Zone Table" is opened automatically in the default browser after the query is finished.
    1. Path Type Name
      $env:temp\time_zones.html HTML-file time_zones.html
      $env:temp\time_zones.csv CSV-file time_zones.csv

Notes

⚠️
  • Please note that all the parameters can be used in one query command and that each of the parameters can be "tab completed" before typing them fully (by pressing the [tab] key).

  • Please also note that the two files are created in a directory, which is end-user settable in each query command with the -Path parameter. The default save location is defined with the $Path variable (at line 12) and the -Path parameter also has an alias called -ReportPath. The default save location $env:temp variable points to the current temp folder. The default value of the $env:temp variable is C:\Users\<username>\AppData\Local\Temp (i.e. each user account has their own separate temp folder at path %USERPROFILE%\AppData\Local\Temp). To see the current temp path, for instance a command

    [System.IO.Path]::GetTempPath()

    may be used at the PowerShell prompt window [PS>]. To change the temp folder for instance to C:\Temp, please, for example, follow the instructions at Temporary Files Folder - Change Location in Windows, which in essence are something along the lines:
    1. Right click on Computer and click on Properties (or select Start β†’ Control Panel β†’ System). In the resulting window with the basic information about the computer...
    2. Click on Advanced system settings on the left panel and select Advanced tab on the resulting pop-up window.
    3. Click on the button near the bottom labeled Environment Variables.
    4. In the topmost section labeled User variables both TMP and TEMP may be seen. Each different login account is assigned its own temporary locations. These values can be changed by double clicking a value or by highlighting a value and selecting Edit. The specified path will be used by Windows and many other programs for temporary files. It's advisable to set the same value (a directory path) for both TMP and TEMP.
    5. Any running programs need to be restarted for the new values to take effect. In fact, probably also Windows itself needs to be restarted for it to begin using the new values for its own temporary files.

Examples

πŸ“– To open this code in Windows PowerShell, for instance:

  1. ./Get-TimeZoneTable
    Run the script. Please notice to insert ./ or .\ before the script name. Uses the default location ($env:temp) for storing the generated HTML Time Zone Table and the adjacent CSV-file to. Outputs the Time Zone Table also in in a pop-up window (Out-GridView). The data is sorted by Date (Current), Time (Current) and Time Zone Id in an ascending order.
  2. help ./Get-TimeZoneTable -Full
    Display the help file.
  3. ./Get-TimeZoneTable -Path "C:\Scripts"
    Run the script and store the two Time Zone Table files to C:\Scripts. The output is sorted, as per default, on the properties Date (Current), Time (Current) and Time Zone Id in an ascending order. Since the -Path variable has an alias of -ReportPath, a command

    ./Get-TimeZoneTable -ReportPath "C:\Scripts"

    will do the exactly same thing. Please note that the -Path is not mandatory in this example and that the quotation marks can be left out, since the path name doesn't contain any space characters (./Get-TimeZoneTable C:\Scripts).
  4. ./Get-TimeZoneTable -Path E:\chiore -Sort psdrive -Descending
    Run the script and save the files to E:\chiore. Sort the data based on the "PSDRIVE" column and arrange the rows as descending so that the last alphabets come to the top and first alphabets will be at the bottom. To sort the same query in an ascending order the -Descending parameter may be left out from the query command (./Get-TimeZoneTable -Path E:\chiore -Sort psdrive).
  5. ./Get-TimeZoneTable -Path C:\Scripts -Sort daylight -Descending
    Run the script and save the HTML Time Zone Table and the adjacent CSV-file to C:\Scripts. Sort the data by the column name "Daylight Saving Time (in system language)" in a descending order. This command will work, because daylight is defined as an alias to the "Daylight Saving Time (in system language)" in the script. Please also note, that -Path can be omitted in this example, because a command

    ./Get-TimeZoneTable C:\Scripts -Sort daylight -Descending

    in essence, has an exact same outcome.
  6. Set-ExecutionPolicy remotesigned
    This command is altering the Windows PowerShell rights to enable script execution. Windows PowerShell has to be run with elevated rights (run as an administrator) to actually be able to change the script execution properties. The default value is "Set-ExecutionPolicy restricted".

    Parameters:

      Restricted Does not load configuration files or run scripts. Restricted is the default execution policy.
      AllSigned Requires that all scripts and configuration files be signed by a trusted publisher, including scripts that you write on the local computer.
      RemoteSigned Requires that all scripts and configuration files downloaded from the Internet be signed by a trusted publisher.
      Unrestricted Loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the Internet, you are prompted for permission before it runs.
      Bypass Nothing is blocked and there are no warnings or prompts.
      Undefined Removes the currently assigned execution policy from the current scope. This parameter will not remove an execution policy that is set in a Group Policy scope.

    For more information, please type "help Set-ExecutionPolicy -Full" or visit Set-ExecutionPolicy.

  7. New-Item -ItemType File -Path C:\Temp\Get-TimeZoneTable.ps1
    Creates an empty ps1-file to the C:\Temp directory. The New-Item cmdlet has an inherent -NoClobber mode built into it, so that the procedure will halt, if overwriting (replacing the contents) of an existing file is about to happen. Overwriting a file with the New-Item cmdlet requires using the Force.
    For more information, please type "help New-Item -Full".

Contributing

Find a bug? Have a feature request? Here is how you can contribute to this project:

contributing Bugs: Submit bugs and help us verify fixes.
Feature Requests: Feature request can be submitted by creating an Issue.
Edit Source Files: Submit pull requests for bug fixes and features and discuss existing proposals.

www

www Script Homepage
Josh Free: Exploring Windows Time Zones with System.TimeZoneInfo
Martin Pugh: Get-FolderSizes
CB.: Dynamic parameter accessing default value
PowerTip: Use PowerShell to retrieve the date and time of the given time zone ID
about_Preference_Variables
Windows PowerShell: Build a Better Function
ValidateSet Attribute Declaration
about_Functions_Advanced_Parameters
PowerShell: Advanced Function Parameter Attributes
Windows PowerShell Tip of the Week
Windows PowerShell: Writing Regular Expressions
Regular expressions in PowerShell and Perl
ASCII Art: http://www.figlet.org/ and ASCII Art Text Generator

Related scripts

www Get-AsciiTable
Get-BatteryInfo
Get-ComputerInfo
Get-DirectorySize
Get-InstalledPrograms
Get-InstalledWindowsUpdates
Get-RAMInfo
Get-TimeDifference
Get-UnusedDriveLetters
Update-AdobeFlashPlayer

About

Generates a Time Zone table with current date and time in each Time Zone and exports it to a HTML- and a CSV-file (a Windows PowerShell script).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published