Does powershell have associative arrays?

George Mauer picture George Mauer · Oct 1, 2009 · Viewed 48.1k times · Source

I am writing a function that returns an id, name pair.

I would like to do something like

$a = get-name-id-pair()
$a.Id
$a.Name

like is possible in javascript. Or at least

$a = get-name-id-pair()
$a["id"]
$a["name"]

like is possible in php. Can I do that with powershell?

Answer

Doug Finke picture Doug Finke · Oct 2, 2009

also

$a = @{'foo'='bar'}

or

$a = @{}
$a.foo = 'bar'