How to work the timezone using PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

To get the timezone of the System, you can use the Get-TimeZone command.

Example

PS C:\> Get-TimeZone

Id                         : Mountain Standard Time
DisplayName                : (UTC-07:00) Mountain Time (US & Canada)
StandardName               : Mountain Standard Time
DaylightName               : Mountain Daylight Time
BaseUtcOffset              : -07:00:00
SupportsDaylightSavingTime : True

To Set the TimeZone of the System, you can you the ID or the Name of the timezone.

Example

PS C:\> Set-TimeZone -Id "Pacific Standard Time" -PassThru
Id                         : Pacific Standard Time
DisplayName                : (UTC-08:00) Pacific Time (US & Canada)
StandardName               : Pacific Standard Time
DaylightName               : Pacific Daylight Time
BaseUtcOffset              : -08:00:00
SupportsDaylightSavingTime : True

To retrieve the list of all the available timezones we need to use System.TimeZoneInfo .net class and method GetSystemTimeZones().

[System.TimeZoneInfo]::GetSystemTimeZones() |ft -AutoSize

Output

raja
Published on 09-Nov-2020 09:36:10
Advertisements