use*_*125 1 powershell replace
我有一个包含以下内容的 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"
}
}]
}
}
Run Code Online (Sandbox Code Playgroud)
我想每天使用 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
Run Code Online (Sandbox Code Playgroud)
小智 5
第一步是将内容转换为 json:
$json = Convertfrom-json (get-content "\\path\To\Json\File.json")
Run Code Online (Sandbox Code Playgroud)
然后根据需要编辑值:
$json.engineconfiguration.Components.Parameters.LogDirectoryPath = "C:\log\$(Get-Date -Format 'yyyy-MM-dd')"
Run Code Online (Sandbox Code Playgroud)
然后将其写回文件:
ConvertTo-Json $json -Depth 4 | Out-File C:\ProgramData\Temp\test.txt -Force
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5262 次 |
| 最近记录: |