import csv and parse


Im new at powershell and would like to import and parse the following csv file


123456;“06/11/2019 07:55:20”;AAAA;BBBB



06/11/2019 07:55:20,AAAA


How do I go about this?




What have you tried so far? You might start with learning the very basics of Powershell.

And please - format your code as code using the code tag button (pre). Thanks

I’d recommend starting (for the current problem) with Get-Help Import-Csv

For a general path to mastering PowerShell I’d recommend starting with :slight_smile:

I am parsing the data as required (displayed in the console) with the following, but cant seem to get the data to export


Import-CSV -Path “C:\Temp\Test.csv” -Delimiter “;” | select TimeStr,Value

This export -csv is not working - any suggestions?

Export-CSV -Path C:\Temp\Test_Out.csv –NoTypeInformation


Does it work as expected? Are you meeting the requirements?

I have finally got PS working… This is what I came up with. The question is, is the best way of achieving the parsing?

Thanks for your comments


Import-CSV -Path “C:\Temp\Test.csv” -Delimiter “;” | select TimeStr,Value |

export-csv -path C:\Temp\Test_Out.csv –NoTypeInformation
(GC $file) | % {$_ -replace ‘"’, ‘’} > $file


Hi there, nice that you found the solution. I don’t know why you get ; as delimiter, but you can force any character to be delimiter with -delimiter argument

Import-CSV -Path “C:\Temp\Test.csv” -Delimiter “;” | select TimeStr,Value | export-csv -path C:\Temp\Test_Out.csv –NoTypeInformation -delimiter ‘,’

How can I change the date format of my output csv to have the timestamp in either AM PM?


This is what Im currently outputting with my script

18/11/2019 12:55:20,725.48


I would like

18/11/2019 12:55:20 p.m,725.48

[datetime]::ParseExact('18/11/2019 21:55:20','dd/MM/yyyy HH:mm:ss',$null).tostring('dd/MM/yyyy hh:mm:ss tt')
18/11/2019 09:55:20 PM

ok, turns out my timstamp in the csv file was 24:00 hrs so I solved with the following script.



Import-CSV -Path “C:\Temp* Test.csv” -Delimiter “;” | ForEach-Object {
$.TimeStr = (Get-Date $.TimeStr).ToString(“dd-MM-yyyy HH:mm:ss”)
} | select TimeStr,Value |
export-csv -path C:\Temp\Test_Out.csv –NoTypeInformation

$arr = New-Object System.Collections.ArrayList

(GC $file) | % {$_ -replace ‘"’, ‘’} > $file


The last task I need to achieve is to process multiple CSV’s that are in the same folder (all CSV’s are the same format, except the data stamp and values are different)

What is the best way of achieving this? Any suggestions?

This will get the path of all *.csv in your folder (and subfolders) then execute Import-Csv cmdlet on all.

(Get-ChildItem -path C:\Temp\ -Recurse -Filter *.csv).FullName | Import-Csv