Adding quotations around path on childitem export

I have the following command:

$paths = foreach($folder in $csv.name){get-childitem -path "p:projectsarchiv$folder" -Recurse | foreach { "$($_.FullName),$($_.lastWritetime)"}} 

I export the variable to a textfile and then open it in excel. There are commas in the foldernames of the Paths (Fullname) that I’m exporting. This is a problem when I use the “text in column” function in Excel.

My idea was to either add quotations around the paths or change the delimiter. I guess I’d have to use export-csv for that but

$paths | export-csv c:temptest.csv 

does not work. I only get a list of numbers with Header “length”.

$path >> c:temptest.csv 

That works but I don’t know how to add quotations or change the delimiter either.

Can you help me with the Syntax to add quotations around the path or helping find out why the csv export doesn’t work?

EDIT: It works when I simply add quotes to Fullname.

$paths = foreach($folder in $csv.name){Write-Host $folder; get-childitem -path "p:projectsarchiv$folder" -Recurse | foreach { "'$($_.FullName)',$($_.lastWritetime)"}; Write-Host "Finished"} 

It does not work if I add the quotes to lastwritetime though. I tried to escape it with ` but that didn’t help. It’s enough for my purposes but I wouldn’t know how to work it out if I had to add the quotes for every column.

submitted by /u/aemmeroli
[link] [comments]

Leave a Reply