Format date from Select-Object

Welcome Forums General PowerShell Q&A Format date from Select-Object

This topic contains 1 reply, has 2 voices, and was last updated by

2 years, 4 months ago.

  • Author
  • #58346

    Points: 0
    Rank: Member

    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

    Points: 1,184
    Helping Hand
    Rank: Community Hero

    You can use calculated properties to achive this.


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

The topic ‘Format date from Select-Object’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort