Sending original, no typo here
Try this:
$array1 = , 2
$array2 = 1, 3, 5, 7 ,9
$array3 = 'abc', 'def', 'xyz'
$hash1 = @{
'EmptyArray' = @();
'Singleton' = $array1;
'OddNumbers' = $array2;
'LetterGroups' = $array3
}
$hash2 = @{
'Hash1' = $hash1;
'Empty Hash' = @{}
}
# always quote the key name when using array indexing
$hash2.Hash1['Singleton']
# use string variable expansion to cast the array as [String]
"$($hash2.Hash1.LetterGroups)"
# get the fourth element of OddNumbers array
$hash2.Hash1.OddNumbers[3]
# if key name contains spaces use quotes
$hash2.'Empty Hash'
$hash2.Hash1
$hash2
Read about Hash tables:
help about_Associative_Array
Read about Arrays:
help about_Array
# - - - - - - - - #
PowerShell les you create custom objects with Add-Member:
$collection1 = @()
$object = New-Object psObject
# using parameter names
Add-Member -MemberType NoteProperty -Name 'Empty Array' -Value @() -InputObject $object
# passing first three parameters by position
Add-Member NoteProperty Singleton @(, 2) -In $object
# using wildcard in -MeberType parameter
Add-Member N* OddNumbers 1, 3, 5, 7 ,9 -In $object
# using the int value of -MemberType parameter
Add-Member 8 LetterGroups 'abc', 'def', 'xyz' -In $object
$collection1 += $object
$object = New-Object psObject
Add-Member N* Empty $null -In $object
Add-Member 8 Collection1 $collection1 -In $object
$collection2 = @(), $object
$collection2
# using array indexing
$collection2[1].collection1[0].Singleton
# use string variable expansion to cast the array as [String]
"$($collection2[1].collection1[0].LetterGroups)"
# get the fourth element of OddNumbers array
$collection2[1].collection1[0].OddNumbers[3]
--
Kiron