leeand00
leeand00

Reputation: 26392

Adding a value to an existing array within a hash in powershell?

Say I have something like:

$funkyHash = @{
    "Z28" = @(13251, 13458, 78910)
    "Z14" = @(12356, 12348)
    "z15" = @(12344)
}

How do I for instance, pull out the "z15" array, add a value, lets say 456, and make sure that it results in:

$funkyHash = @{
    "Z28" = @(13251, 13458, 78910)
    "Z14" = @(12356, 12348)
    "z15" = @(12344, 456)
}

...within funkyHash?

Upvotes: 0

Views: 410

Answers (1)

Max
Max

Reputation: 771

I've tried as per below, and seems working.

> $funkyHash

Name                           Value
----                           -----
z15                            {12344}
Z28                            {13251, 13458, 78910}
Z14                            {12356, 12348}

> $funkyHash["z15"] += @(999)
> $funkyHash

Name                           Value
----                           -----
z15                            {12344, 999}
Z28                            {13251, 13458, 78910}
Z14                            {12356, 12348}

Upvotes: 2

Related Questions