Get-ChildItem Compare-Object Folders and Files Date and Name, But Filter Files

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of random commandline random commandline 3 weeks ago.

  • Author
    Posts
  • #67692
    Profile photo of Clifford Smith
    Clifford Smith
    Participant

    I'm learning about and writing my first PowerShell program, where I compare folders and files on two drives to find differences based on name and date. I'm checking a library of folders and files for differences between shipping and beta versions of software to help focus testing.

    If I find an "unpaired" folder, then I don't want to list both the folder and its files in my output of differences. In this case, it is enough to know that there is a difference at the folder level. I'm checking a library of folders and files between shipping and beta versions of software to help focus testing. In the folders, there are only files, not subfolders.

    I don't know how to filter the duplicate information. In the final version of my PowerShell program, I'll write the results (full pathnames) to a file. Will I have more powerful filtering capabilities if I store the Get-ChildItem and Compare-Object results in files or arrays rather than variables?

    This is a simplified program that I'm writing to test ideas for the final program:

    I've included my console output and pointed out the extraneous information in a comment block following the test program.

    Thanks for your help.

  • #67728
    Profile photo of random commandline
    random commandline
    Participant

    This will export full paths to a csv file.

    # Get folders
    $ship = Get-ChildItem "F:\Shipping" -Recurse
    $test  = Get-ChildItem "C:\Testing" -Recurse
    
    # Compare name and date then export paths
    Compare-Object $ship $test -Property Name,
    LastWriteTime -PassThru | Select-Object FullName |
    Export-Csv .\compare.csv -NoTypeInformation
    

You must be logged in to reply to this topic.