r/PowerShell • u/TTwelveUnits • 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
Johnis this just syntactical sugar, or something? thought i would have to do this:
$obj[Name]
23
Upvotes
View all comments
Show parent comment
2
u/purplemonkeymad Nov 22 '24
Yea that's fair, it can be confusting, but I see dictionaries used the same as a psobject often so I don't think it's that unusual to use them as such. The main problem is they don't work the same in the pipeline for parameter binding.