我想通過參數傳入的名稱引用哈希表。使用變量來引用哈希表的內容
Ex。
TestScript.Ps1 -specify TestDomain1,TestDomain2
內容TestScript.ps1的:
param(
[string[]]$specify
)
$TestDomain1 = @{"Name" = "Test1", "Hour" = 1}
$TestDomain2 = @{"Name" = "Test2", "Hour" = 2}
foreach($a in $specify)
{
write-host $($a).Name
#This is where I would expect it to return the Name value contained in the respective
# hash table. However when I do this, nothing is being returned
}
是否有另一種方式來這樣做是爲了獲得這些價值?有沒有更好的方法,而不是使用哈希表?任何幫助,將不勝感激。
運行此代碼時,您不知道語法錯誤嗎?哈希表文字是 = ... –
BartekB
修復了OP的語法錯誤。 – dugas