I have a script that extracts some values from a list of log files. Each value is inserted in an array.
At the end of the script I'd like to combine each line of each array and export them in an excel file.
Here is the script:
while (1) {
clear
$list = New-Object System.Collections.ArrayList
$list2 = New-Object System.Collections.ArrayList
$list3 = New-Object System.Collections.ArrayList
$list4 = New-Object System.Collections.ArrayList
$dir_to_look = "C:\test"
$30_days_backdate=$(Get-Date).Adddays(-30) ####pour tester
$contenu = Get-childitem $dir_to_look -recurse LOG20* |where { $_.lastwritetime -gt $30_days_backdate }| Get-Content
############### Fichier log du jour
foreach ($line in $contenu) {
if ($line -match "CFTT82E.*IDT=(.+?)\b.*") {
$str = $line.Split(' ')
$props = [ordered]@{
Heure = $str[2]
Date = $str[1] ############ Heure où le message est apparu ######################
}
$heure_plantage=$str[2]
$date_du_plantage=$str[1]
$idt = $matches[1]
if(!$list.contains($idt)){
if ($line -match "CFTT82E.*PART=(.+?)\b.*") { ############### Récuperrer le nom_du_partner #################
$part = $matches[1]
}
$list.add($idt)
$list2.add($heure_plantage)
$list3.add($part)
$list4.add($date_du_plantage)
$conver=$list4 |Foreach-Object {$_ -replace "([0-9]+)/+([0-9]+)/+([0-9]+)", '$3-$2-$1'} # conversion date en EU
}
}
}
###visual test of the array values
write-host "$list"
write-host "$list2"
write-host "$list3"
write-host "$conver"
break }The output of these arrays is this (may contain more values in each line.I left only four values for the purpose of this question):
A1512201 A1512204 A1512203 A1512205 12:20:06 12:20:08 12:20:16 12:20:25 TOTO TITI DPFDDFL PACKA 15-01-14 12-03-14 13-03-14 13-03-14So, I'd like to have the following output in the right order:
DATE HOUR IDT PARTNER 15-01-14 12:20:06 A1812201 TOTO 12-03-14 12:20:08 B1212204 TITI 13-03-14 12:20:16 A1912203 DPFDDF 13-03-14 12:20:25 A2012205 PACKAAny suggestion is welcome,
Thank you in advance.