将值添加到Powershell哈希中的现有数组?

时间:2019-01-24 19:55:46

标签: powershell

说我有类似的东西:

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

例如,如何提取"z15"数组,添加一个值,说456,并确保其结果为:

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

...在funkyHash中?

1 个答案:

答案 0 :(得分:2)

我已经按照下面的方法尝试过,并且似乎可以正常工作。

> $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}