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/McAUTS Nov 22 '24
Thanks for that post. Just had this use case with a dictionary e.g.
$exampleDict.Values. In VSCode and Terminal nothing shows the methodget_Values(). Not evenGet-Member. I typed it in and magically the method is valid and returned the values.Why is it superior and why is it "hidden"?