SP7
SP7

Reputation: 13

PowerShell accessing data from hashtable inside hashtable

I have 5 hash tables:

$Monday = @{RUG = "";NRH1 = "";NRH2 = "";ELM = "";BAGVAGT = ""}
$Tuesday = @{RUG = "";NRH1 = "";NRH2 = "";ELM = "";BAGVAGT = ""}
$Wednesday = @{NRH1 = "";NRH2 = "";ELM = "";BAGVAGT = ""}
$Thursday = @{NRH1 = "";NRH2 = "";ELM = "";BAGVAGT = ""}
$Friday = @{NRH1 = "";NRH2 = "";ELM = ""}

That get filled with data. And I can get data out from these either one at at time with $Monday.RUG or all with $Monday | out-string. No problem there.

I'm going to combine those in another hash table 100 times with different data. So it will be like this:

$Week = @{
1 = @{mo=$Monday;tu=$Tuesday;we=$Wednesday;th=$Thursday;fr=$Friday;val=$value}
2 = @{mo=$Monday;tu=$Tuesday;we=$Wednesday;th=$Thursday;fr=$Friday;val=$value}
}

And so on, until I have 100 different weeks with different values (value will be a calculated number)

But the question is. How do I access the items in the hashtables inside the $week hashtable?

Is there a direct way like $week.1.mo ? or do you need to use a loop?

Upvotes: 1

Views: 209

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 58931

You can access it using:

$Week[1].mo 

Upvotes: 1

Related Questions