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

1

u/fennecdore Nov 22 '24

hmm not sure if I'm understanding you right but for me this work :

$hashmap = @{food = "bar"}
$variable = "food"

and

$hashmap.$variable.length

returns 3 for me