You want a HashTable:
$ServiceArray = @{
Ben = 'gold';
Harry = 'red';
Joe = 'green';
Time = 'yellow';
}
$ServiceArray.Ben
# Result:
# gold
If you want more "columns", you can create a HashTable
of PSCustomObject
. You can build PSCustomObject
objects using a HashTable
, as @mjolinor mentioned.
$ObjectList = @{
Ben =
[PSCustomObject]@{
Color = 'Gold';
Shape = 'Square';
};
Harry =
[PSCustomObject]@{
Color = 'Red';
Shape = 'Round';
};
Joe =
[PSCustomObject]@{
Color = 'Green';
Shape = 'Triangle';
};
Tim =
[PSCustomObject]@{
Color = 'Yellow';
Shape = 'Rectangle';
};
};
# Syntax: Use dot-notation to access "Ben"
$ObjectList.Ben.Color; # Gold
$ObjectList.Ben.Shape; # Square
# Different syntax: Use the string indexer to access "Ben"
$ObjectList['Ben'].Color; # Gold
$ObjectList['Tim'].Shape; # Rectangle