您可以使用正则表达式来捕获这些字段:
$content = Get-Content 'your_log_path' -raw
$regex = 'Line\s+(\d+):\s+([^;]+);([^;]+);([^;]+);(.+)'
[regex]::Matches($content, $regex) | ForEach-Object {
[PsCustomObject]@{
Line = $_.Groups[1].Value
Date = $_.Groups[2].Value
Time = $_.Groups[3].Value
Type = $_.Groups[4].Value
Description = $_.Groups[5].Value
}
}
输出:
Line : 33043
Date : 17/07/2016
Time : 13:26:45
Type : GetMasterOrderNo
Description : Master Order No is : 1117103907 for SoSupplierOrderNo, 1117103907
Line : 33048
Date : 17/07/2016
Time : 13:26:45
Type : AddAutoPurchHdr
Description : Could not save PurchHdr record - The supplier order number has already been used in Delivery Note No.1117103907 (Order No.1117103907), Supplier SupplierName(51)
Line : 33049
Date : 17/07/2016
Time : 13:26:45
Type : ImportASN
Description : ConvertASNFiles: Failed to import GRN1171_0000700384_1117103907.xml. Could not save PurchHdr record - The supplier order number has already been used in Delivery Note
No.1117103907 (Order No.1117103907), Supplier SupplierName(51)
正则表达式:
Line\s+(\d+):\s+([^;]+);([^;]+);([^;]+);(.+)
