PowerShell: Hashtable Key / Property Name Clash

By Xah Lee. Date: .

Key Name Conflict with Property Name

In the convenient Member-access operator form

hashtable.key

If a key has same name as a hashtable property name, the hashtable key name has priority.

To access property, use .psbase.propertyName

# this hashtable, has a key named keys, which clash with the method name named keys
$dict = [ordered] @{"keys" = 1; "b" = 2; }

# key name has priority
$dict.keys
# 1

# to access the method name, add .psbase.
Write-Host $dict.psbase.keys
# keys b

PowerShell Hashtable, Dictionary