Get-ChildItem Dir Listing RRS feed

  • Question

  • Hi,

    I need to generate a report for the below directory structure.

    "12/1/2018 12:00:30 AM","A"
    "12/1/2018 12:00:30 AM","B"
    "12/1/2018 12:00:30 AM","C"
    "12/1/2018 12:00:30 AM","D"
    "12/2/2018 12:00:36 AM","A"
    "12/3/2018 12:00:45 AM","M"

    I need the report to extract only those entries which  have the latest LastWriteTime. In the above example, I don't need "12/2/2018 12:00:36 AM","A" to show up on my report. I am using the Get-ChildItem and did not find an Input parameter to extract this data.

    Also is it possible to only extract the Date Field? I don't need the time on my report.1

    Get-ChildItem -Path D:\Syslogd\Logs\* -Recurse | Select-Object LastWriteTime,Name | Export-Csv -Path D:\Report.csv -Encoding ascii -NoTypeInformation

    Thanks for Looking.

    Friday, March 20, 2020 8:15 PM

All replies

  • You will have to group the items by folder or you will have to query each folder independently.

    Start with this:

    Get-ChildItem D:\Syslogd\Logs -Directory -Recurse |
            $_ | Get-ChildItem -File | 
                Sort-Object LastWriteTIme -Descending |
                Select-Object -First 1


    • Edited by jrv Friday, March 20, 2020 8:28 PM
    Friday, March 20, 2020 8:24 PM