Param( $textlogfile = "$HOME\Desktop\Logs.txt" ) $collection=@() #########trim the white spaces lines from the structured text######## $content = (gc $textlogfile ) | ? {$_.trim() -ne "" } ######Calculate the number of structured fields, in this case its 9, so $i=$i+9 for($i=0;$i -lt $content.length;$i=$i+5) { $Timestamp = $content[$i] $Time=$Timestamp.split(":")[1].trim() $Sender = $content[$i+1] $Send=$Sender.split(":")[1].trim() $MessageSubject = $content[$i+2] $MessSub=$MessageSubject.split(":")[1].trim() $Recipients = $content[$i+3] $Recip=$Recipients.split(":")[1].trim() $EventID = $content[$i+4] $Event=$EventID.split(":")[1].trim() $coll = "" | select Timestamp,Sender,MessageSubject,Recipients,EventID $coll.Timestamp = $Time $coll.Sender = $Send $coll.MessageSubject = $MessSub $coll.Recipients = $Recip $coll.EventID = $Event $collection +=$coll } $collection | export-csv $HOME\Desktop\Converted-Logs.csv -notypeinformation