我有一个具有以下内容的json文件-
{
"IsEnabled": true,
"EngineConfiguration": {
"PollInterval": "00:00:15",
"Components": [{
"Id": "Logs",
"FullName": "AWS.EC2.Windows.CloudWatch.CustomLog.CustomLogInputComponent,AWS.EC2.Windows.CloudWatch",
"Parameters": {
"LogDirectoryPath": "C:\\log\\2018-05-25",
"TimestampFormat": "yyyy-MM-dd HH:mm:ss",
"Encoding": "UTF-8",
"Filter": "",
"CultureName": "en-US",
"TimeZoneKind": "UTC",
"LineCount": "1"
}
}]
}
}
我想使用Powershell使用托管任务每天替换此日期(在LogDirectoryPath中提到)。
有人可以提供使用Powershell每天更换它的最简单方法吗?
最佳答案
该脚本将帮助您更新日志目录。
脚步:
脚本:
$JsonData = Get-Content $JsonFilePath -raw | ConvertFrom-Json
$JsonData.update | % { if($JsonData.engineconfiguration.Components.Parameters.LogDirectoryPath)
{
$JsonData.engineconfiguration.Components.Parameters.LogDirectoryPath = "C:\log\$(Get-Date -Format 'yyyy-MM-dd')"
}
}
$JsonData | ConvertTo-Json -Depth 4 | set-content $JsonFilePath
关于powershell - 使用PowerShell替换JSON中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50521035/