Monday, 26 August 2013

Use variable to refer to contents of hash table

Use variable to refer to contents of hash table

I'm trying to refer to a hash table by name that is passed in via a
parameter.
Ex.
TestScript.Ps1 -specify TestDomain1,TestDomain2
param(
[string[]]$specify
)
$TestDomain = @{"Name" : "Test1", "Hour" : 1}
$TestDomain = @{"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
}
Is there another way to be doing this to get these values? Is there a
better method rather than using the hash tables? Any help would be
appreciated.

No comments:

Post a Comment