Format date from Select-Object

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Olaf Soyk Olaf Soyk 2 weeks, 2 days ago.

  • Author
    Posts
  • #58346
    Profile photo of Erick
    Erick
    Participant

    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

  • #58349
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant

    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

You must be logged in to reply to this topic.