【发布时间】:2013-08-29 07:53:55
【问题描述】:
我正在尝试按名称引用通过参数传入的哈希表。
例如
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
}
还有其他方法可以获取这些值吗?有没有比使用哈希表更好的方法?任何帮助将不胜感激。
【问题讨论】:
-
运行此代码时不会出现语法错误吗?哈希表文字是
= ... -
修复了 OP 的语法错误。
标签: variables powershell hashtable