r/PowerShell • • Nov 22 '24

Question Hashtable syntax

why is it when i declare as hashtable, I can access its properties like an object?

PS C:\Users\john> $obj = @{
>>     Name = "John"
>>     Age = 30
>> }
PS C:\Users\john> $obj.Name
John

is this just syntactical sugar, or something? thought i would have to do this:

$obj[Name]
23 Upvotes

16 comments sorted by

View all comments

Show parent comment

2

u/jborean93 Nov 22 '24

The ordering of parameters doesn’t really matter as they will bind in the exact same as if they we’re ordered differently. If using an array splat then the order matters because the values are bound positionally but using a hashtable or ordered dict will be the same splat wise.