我想问您有关哈希表(powershell)中的动态嵌套键的问题。 我已经做过一些研究,但找不到答案。
# I got this hash structure,works fine
$Hashtable = @{}
$Hashtable.Maincategory = @{}
$Hashtable.Maincategory.Subcategory = @{}
$Hashtable.Maincategory.Subcategory.MyProperty = @{ 'property' = 'value'}
$Hashtable.Maincategory.Subcategory.MyProperty
Name Value
---- -----
property value
# I want dynamic path to my property
$MainAndSubCategory = [string]'Maincategory.Subcategory'
$Hashtable.$MainAndSubCategory.MyProperty # doesn't work
$Hashtable."$MainAndSubCategory".MyProperty # doesn't work
$Hashtable."$($MainAndSubCategory)".MyProperty # doesn't work
$Hashtable."$(Get-Variable -Name 'MainAndSubCategory' -Valueonly)".MyProperty # doesn't work
请多多指教,谢谢。