I need some help splitting a column into multiple columns in the CSV file using powershell.
These are outlook task completion emails, and we are gathering task statistics. I need to extract the date completed and actual work data from the body column.
Here is one entry for the csv file
Subject,Body,From: (Name)
Task Completed: lprab: 160323-092321 - PCMS:Review/SGCE:Révision,"
Jon York
-----Original Task-----
Subject: lprab: 160323-092321 - PCMS:Review/SGCE:Révision
Priority: Normal
Start date: Wed 2016-03-23
Due date: Wed 2016-03-23
Status: Completed
% Complete: 100%
Date completed: Wed 2016-03-23
Actual work: 15 minutes
Requested by: Internet Content-PAB / Contenu d'Internet-DGAP
------------
","York, Jonathan"
So far, I've managed to split the body at the date completed part using this code here
ForEach-Object {
$_.Body,$tempDateCompleted=$_.Body -split "Date completed: ",2
$_ | Select-Object *,@{Name="DateCompleted";Expression={$tempDateCompleted}}
} #| export-csv
But I can't then get the actual date afterwards because doing
ForEach-Object {
$_.Body,$tempDateCompleted=$_.Body -split "Date completed: ",2
$_ | Select-Object *,@{Name="DateCompleted";Expression={$tempDateCompleted}}
$_.DateCompleted,$tempActualWork=$_.Body -split "Actual work: ",2
$_ | Select-Object *,@{Name="ActualWork";Expression={$tempActualWork}}
} #| export-csv
give me this error
Property 'DateCompleted' cannot be found on this object; make sure it exists and is settable.
At line:82 char:8
+ $_. <<<< DateCompleted,$tempActualWork=$_.Body -split "Actual work: ",2
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
My ultimate goal would be to have the following output
Subject, From, DateCompleted, ActualWork "Task name","Jon York","2016-03-23","15 minutes"
Thanks!