Author Posts

November 21, 2016 at 7:14 pm

Hello I currently have the code, the results will be exported to a csv file

$GetInventory = get-childitem -Recurse -file | Select-Object FullName, Name, Extension, LastWriteTime, CreationTime, LastAccessTime, Length
$GetInventory | Export-CSV $SavePath

Additionally, depending on the task, the code will include | ? {$_.LastWriteTime -lt (Get-Date).AddYears(-7)}

What I want to achieve is for the CSV file to output the date in mm\dd\yyyy format, I dont require the time. I have tried the -format D but i'm placing it in the wrong spot.

" A parameter cannot be found that matches parameter name 'format'."

How can I achieve the desired results.
Thank you

November 21, 2016 at 7:35 pm

You can use calculated properties to achive this.

Example:

... your code here | Select-Object FullName, Name, Extension, @{Name='LastWriteDate';Expression={Get-Date $_.LastWriteTime -Format 'MM\dd\yyyy'}, CreationTime, LastAccessTime, Length