Hi All,
I’ve run into an issue which is killing my productivity! I’m trying to create a hash table with a dynamic key name. I’m not sure if this isn’t possible, or if I’m not doing it correctly.
Here’s what works. There ‘name’ is static.
$name = "Roy"
$age = 20
weight = 150
$hash = @{
name = @{
Age = $age
Weight = $weight
}
}
$hash.Name.Age
20
Here’s what won’t work
$name = "Roy"
$age = 20
weight = 150
$hash = @{
$name = @{
Age = $age
Weight = $weight
}
}
$hash.Roy.Age
(No output)
Is it possible to dynamically use a variable as a key in powershell? If not, what are some other options?