◐ Shell
clean mode source ↗

Respect -ListAvailable:$false in Get-TimeZone by yotsuda · Pull Request #26463 · PowerShell/PowerShell

PR Summary

This PR fixes the issue where -ListAvailable:$false is not respected in Get-TimeZone, causing it to behave the same as -ListAvailable:$true.

Fixes #26462
Related to #25242

PR Context

When -ListAvailable:$false is explicitly specified for Get-TimeZone, the cmdlet incorrectly returns all available time zones instead of returning only the current time zone. This occurs because the code checks ParameterSetName (a string) instead of checking the actual boolean value of the ListAvailable parameter.

This fix changes the condition from checking the parameter set name to directly checking the ListAvailable property value, ensuring that explicit $false values are properly respected.

Changes

  • Modified TimeZoneCommands.cs line 57: Changed if (this.ParameterSetName.Equals("ListAvailable", StringComparison.OrdinalIgnoreCase)) to if (ListAvailable)
  • Added test case in TimeZone.Tests.ps1 to verify -ListAvailable:$false returns only the current time zone

Testing

  • Added new test: "Call with -ListAvailable:$false returns current TimeZoneInfo (not list)"
  • The test verifies that -ListAvailable:$false returns a single TimeZoneInfo object representing the current time zone
  • Pre-fix: Test fails (returns all 142 time zones instead of 1)
  • Post-fix: Test passes (returns 1 current time zone as expected)
  • All existing tests continue to pass

PR Checklist