本文介绍了将哈希表保存为PowerShell对象表示法(PSON)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问题从文件中加载PowerShell哈希表?文档如何将包含PSON格式的哈希表的文件加载到变量中,但是如何将哈希表保存到PSON格式的文件中?
The question Loading a PowerShell hashtable from a file? documents how to load a file that contains a hashtable in PSON format into a variable, but how does one save a hashtable to a file in PSON format?
哈希表:
@{
"name" = "report 0"
"parameters" = @(
@{"name" = "parameter 0"; "default" = 1; "values"=1,2,3,4},
@{"name" = "parameter 1"; "default" = 'A'; "values" = 'A','B','C'}
)
}
推荐答案
尝试使用*-CliXml
cmdlet.保存对象:
Try the *-CliXml
cmdlets. To save the object:
@{
"name" = "report 0"
"parameters" = @(
@{"name" = "parameter 0"; "default" = 1; "values"=1,2,3,4},
@{"name" = "parameter 1"; "default" = 'A'; "values" = 'A','B','C'}
)
} | Export-Clixml -Path c:\hash.xml
要读回去:
Import-Clixml c:\hash.xml
这篇关于将哈希表保存为PowerShell对象表示法(PSON)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!