gpt4 book ai didi

powershell - Powershell ConvertTo-json输出为小写

转载 作者:行者123 更新时间:2023-12-03 00:51:42 26 4
gpt4 key购买 nike

我正在使用下面的命令来生成下面的输出

$VMHost | ConvertTo-json | Out-File -encoding "UTF8" -FilePath  ".\$VMHostName.report"

但我需要小写的所有键和值,如下所示
 "HostNumaStatus": [
{
"ComputerName": "TEMSA10",
"MemoryAvailable": 3119,
"MemoryTotal": 6075,
"NodeId": 0,
"ProcessorsAvailability": "35 41 56 58"
}
]


 "hostnumastatus": [
{
"computername": "TEMSA10",
"memroyavailable": 3119,
"memroytotal": 6075,
"nodeid": 0,
"processoravailability": "35 41 56 58"
}
]

最佳答案

我会使用[Regex]静态方法Replace:

$Json = $VMHost | ConvertTo-Json

[regex]::Replace(
$Json,
'(?<=")(\w+)(?=":)',
{
$args[0].Groups[1].Value.ToLower()

}
)

关于powershell - Powershell ConvertTo-json输出为小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23878240/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com