
PowerShell
- 1 ответ
- 0 вопросов
1
Вклад в тег
$WorkFolder = "c:\WorkFolder"
$LogFile = $WorkFolder + "\" + "sample_0001.log"
$FileContent = (Get-Content $LogFile).Trim()
if (-not ($FileContent -match "</root>$")){$FileContent += "</root>"}
[xml]$XmlFile = $FileContent
$WorkFolder = "c:\WorkFolder"
$ResultFile = "$WorkFolder\result.csv"
Get-ChildItem "$WorkFolder\*.log" | ForEach-Object {
$FileContent = (Get-Content $_).Trim()
if (-not ($FileContent -match "</root>$")){$FileContent += "</root>"}
[xml]$XmlFile = $FileContent
$XmlFile.root.item | Select-Object @(
@{l="date"; e={$_.date}}
@{l="time"; e={$_.time}}
@{l="data1"; e={$_.data1}}
) | Export-Csv -Path $ResultFile -NoTypeInformation -Append -Encoding UTF8
}