我有一个名为$Hash
的哈希表,这是它的结构:
Name Value
---- -----
NTER 1 {[Short, Kill > Dump], [Long, Procces is terminated, then all errors are dumped to a log file1]}
NTER 2 {[Short, Kill > Dump], [Long, Procces is terminated, then all errors are dumped to a log file2]}
NTER 3 {[Short, Kill > Dump], [Long, Procces is terminated, then all errors are dumped to a log file3]}
NTER 4 {[Short, Kill > Dump], [Long, Procces is terminated, then all errors are dumped to a log file4]}
LA2 1 {[Short, Kill > Dump], [Long, Procces is terminated, then all errors are dumped to a log file5]}
LA2 2 {[Short, Kill > Dump], [Long, Procces is terminated, then all errors are dumped to a log file6]}
LA2 3 {[Short, Kill > Dump], [Long, Procces is terminated, then all errors are dumped to a log file7]}
LA2 4 {[Short, Kill > Dump], [Long, Procces is terminated, then all errors are dumped to a log file8]}
我正在尝试使用Long
密钥的值(即:"进程被终止,然后所有错误都被转储到日志文件中…"(,这样我就可以使用它来输入一般事物的值,例如文件名:
$Var| ForEach-Object {
Copy-item -path '..Template 2.svg' -Destination ".($hash.keys.value).svg"
}
做类似$hash.'NTER 1'.keys
的事情不是一种选择,因为在任何给定的时间都可能有多个$hash.<key>
。
上述示例的预期输出应该是.svg
文件路径:
.Procces is terminated, then all errors are dumped to a log file1.svg
.Procces is terminated, then all errors are dumped to a log file2.svg
...
我在访问哈希表中的数据以用于其他命令时遇到了一般问题。
例如,在上面的例子中。我不能做$Hash.keys | ForEach-Object {
,因为这不会给我NTER 1
、LA2 1
等密钥,而是给我一些(System.Collections.Specialized.OrderedDictionary.keys.value)
的字符串所以我必须首先通过$Var = $Hash
创建$var
但即使有这种迂回的做法:
$Var| ForEach-Object {
Copy-item -path '..Template 2.svg' -Destination ".($hash.keys.value).svg"
}
仍然给我一个名为:的文件
.(System.Collections.Specialized.OrderedDictionary.keys.value).svg
我已经自由地在其他论坛上交叉发布了这个问题。
任何帮助都会很棒。
如果您希望检索$hash
中嵌套哈希表的Long
键控条目的值,请跨所有顶级条目:
$hash.Values.Long