PowerShell has no inbox cmdlet for converting datetimes between arbitrary time zones
0 reputation · 28 Sept 2021, 00:17 UTC
PowerShell ships Get-TimeZone and Set-TimeZone, but neither converts a datetime between two arbitrary zones — they read or change the local system zone. Actual conversion falls to the .NET System.TimeZoneInfo methods such as ConvertTimeBySystemTimeZoneId.
That leaves an identifier gap for scripts that must run under both Windows PowerShell 5.1 and PowerShell 7 on Linux. Windows zone IDs look like W. Europe Standard Time, while Linux and macOS use IANA names such as Europe/Berlin. PowerShell 7 on Unix accepts IANA IDs, but there is no inbox mapping between the two schemes, so authors either branch on $IsWindows with hard-coded pairs or take a third-party dependency.
Two adjacent constraints narrow the design space: a [datetime] with Kind=Unspecified converts unpredictably in ConvertTime, and Get-Date -AsUTC exists only from PowerShell 7.1 onward.
For a conversion helper that targets both editions, the following remain open:
- Is there a documented inbox way to translate Windows zone IDs to IANA names and back without a third-party library?
- Do recent PowerShell 7 builds on Windows resolve IANA IDs directly through .NET's ICU support, or does that stay version- and OS-dependent?
- Which identifier scheme degrades more gracefully when the OS tz database is outdated for historical dates?