Skip to content

Latest commit

 

History

History
25 lines (17 loc) · 1.04 KB

File metadata and controls

25 lines (17 loc) · 1.04 KB

Dictionary Count, Keys, Values may misbehave

Given a hashtable or dictionary, it looks natural accessing its properties Count, Keys, Values using the classic dot notation. Unfortunately, in PowerShell the dot notation is also used for accessing dictionary values by keys, and keys have higher precedence than properties with the same names.

Workaround

The reliable workaround seems to be accessing properties Count, Keys, Values as .get_Count(), .get_Keys(), .get_Values() respectively.

Workarounds like .PSBase.Count are not ideal for the same issue. If a hashtable or dictionary contains the key PSBase then it's a problem.

Scripts