2

I have a file data.csv which contains:

2017.11.1,09:55,1.1,1.2,1.3,1.4,1 
2017.11.2,09:55,1.5,1.6,1.7,1.8,2

I want to filter it by yesterday date so I did this:

$Data = Import-Csv $file -Header Date,Time,A,B,C,D,E
$CutOff = (Get-Date).AddDays(-1)
$Data2 = $Data | Where-Object {$_.Date -as [datetime] -gt $Cutoff}
$Data2 | Export-Csv -Path "Date2.csv"

But file data2.csv contains:

#TYPE System.Management.Automation.PSCustomObject
"Date","Time","A","B","C","D","E"
"2017.11.2","09:55","1.5","1.6","1.7","1.8","2"

Which is not the same format than the original one:

  • How to get rid of double quotes
  • How to get rid of the header and type lines
henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
user310291
  • 36,946
  • 82
  • 271
  • 487
  • Take a look at this thread: https://social.technet.microsoft.com/Forums/windowsserver/en-US/f6b610b6-bfb2-4140-9529-e61ad30b8927/how-to-export-csv-without-doublequote?forum=winserverpowershell – Master Yoda Nov 03 '17 at 11:11
  • This is also useful: https://blogs.technet.microsoft.com/heyscriptingguy/2011/11/02/remove-unwanted-quotation-marks-from-csv-files-by-using-powershell/ Good question by the way. – Master Yoda Nov 03 '17 at 11:12
  • 1
    `Export-Csv -Path "Date2.csv" -NoTypeInformation` will remove the Type line – henrycarteruk Nov 03 '17 at 11:18

0 Answers0