Я пытался проанализировать ряд файлов в каталоге для ряда определенных строк.До сих пор при извлечении требуемой информации успешно выполнялось следующее:
Param (
[Parameter(Mandatory=$true)]
[string] $FullyQualifiedPath
)
$OutputFile = "Example.txt" #Adjust as needed
$FullyQualifiedPath = "C:\Location"
$Pat1 = [regex] 'Serial Number'
$Pat2 = [regex] 'Start Time'
$Pat3 = [regex] 'Error Code;'
Remove-Item "$OutputFile"
Get-ChildItem -Path "$FullyQualifiedPath" |
Get-Content | Select-String -Pattern $Pat1,$Pat2,$Pat3 -AllMatches >>$OutputFile
Это дает мне текстовый файл в формате, подобном приведенному ниже:
2018-03-01 11:53:32> Start method command - progress; Serial number of Instrument: InstrumentA
2018-03-01 11:53:36> Main - error; An error occurred while running Vector. The error description is: The instrument was unable to complete
the command.
2018-03-01 11:55:37> Start method command - progress; Serial number of Instrument: InstrumentB
2018-03-01 11:55:42> Execute method - start; Method file C:\Folder\File
2018-03-01 11:55:43> Main - error; An error occurred while running Vector. The error description is: Step cannot start while a verification
or maintenance is outstanding.
Однако эта информация в значительной степенинепригоден для использования в состоянии, в котором он находится.
Можно ли в любом случае изменить вывод, чтобы файл читал, как показано ниже ?
Где каждый код ошибки печатается на новой строке с соответствующим серийным номером иВремя начала?
2018-03-01 11:53:32> Start method command - progress; Serial number of Instrument: InstrumentA | 2018-03-01 11:55:42> Execute method - start; Method file C:\Folder\File | 2018-03-01 11:53:36> Main - error; An error occurred while running Vector. The error description is: The instrument was unable to complete the command.
2018-03-01 11:55:37> Start method command - progress; Serial number of Instrument: InstrumentB | 2018-03-01 11:55:42> Execute method - start; Method file C:\Folder\File | 2018-03-01 11:55:43> Main - error; An error occurred while running Vector. The error description is: Step cannot start while a verification or maintenance is outstanding.
Я новичок в использовании PowerShell, поэтому извиняюсь за свою наивность в этом вопросе.