I have a json file with the following content -
{
"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"
}
}]
}
}
I want to replace this date(mentioned in LogDirectoryPath) everyday using a managed task using powershell.
Can someone please give the easiest way to replace this everyday using powershell?
(Get-Content yourfile) - replace '(?<="LogDirectoryPath": "C:\\\\log\\\\)(?<date>[\d-]+)(?=",)', (Get-Date -Format "yyyy-MM-dd") | Set-Content yourfile
but you should consider using a format like TimestampFormat. Changing the JSON file daily is a code smell. – Lieven Keersmaekers