I have a powershell command using robocopy to list files. I am trying to output to csv but it does not separate the columns as needed. I get two columns where there should be 5. is there a delimiter parameter for out-file
csv?
Here is the current code:
robocopy .\Documents\ NULL /L /S /V /E /BYTES /FP /NC /NDL /XJ /TS /R:1 /W:2 | Out-File -Append -FilePath "c:\beehive_20150608.csv" -Encoding ASCII
I tried export-csv
and it only brings back the string length of the path.
Any suggestions?
I assume you need to list all files under some folder. You can use
Get-ChildItem -Recurse
for that instead ofrobocopy
, filter only files withWhere-Object
then pick only properties you want withSelect-Object
:If you need to use
robocopy
you may try parsing it's output:It's ugly, but should do what you need. I added
/njh
and/njs
arguments to your command line to suppressrobocopy
's header and footer,Where-Object
removes non-matching (empty) lines andForEach-Object
creates object with named properties using$Matches
created by-match
operator used inWhere-Object
.