Seperate column in .CSV output

by Serkantek at 2012-11-21 21:34:46

Hi Guys,

I’m new to powershell scripting and I need some assistance.

I’ve been working on a script to find all files last modified 2009-01-01 and their size. I’ve put together this script which is working but I need to tweak it to seperate the size of the file into a seperate column so I can calculate how big the files are:

Get-ChildItem -Path D:\ -Recurse | Where-Object -FilterScript {($.LastWriteTime -lt "2009-01-01")} | Out-File H:\path.csv

I have also tried:

Get-ChildItem -Path D:\ -Recurse | Where-Object -FilterScript {$
.LastWriteTime -lt "2009-01-01" -and $File.Length} | Out-File H:\path.csv

But both scripts only show the data as one block of data.

Thanks in advance
by Klaas at 2012-11-22 02:03:16
The best way is to select which properties you want and then pipe to export-csv. That creates a real csv, while out-file writes every item as a string.

Get-ChildItem -Path D:\ -Recurse |
Where-Object {$_.LastWriteTime -lt "2009-01-01"} |
select name,lastwritetime,length |
export-csv H]

Please try Get-Help Get-Childitem -Full | more and Get-Help Export-Csv -Full | more to read about all the options and parameters you can add.
by Serkantek at 2012-11-22 13:16:01
Worked a treat.
Read the help files also very helpfully.

Thank you.