Powershell comparing folders

Discussion in 'Scripting' started by EFA11, Jun 28, 2014.

  1. EFA11

    EFA11 Avatar Guru

    Oct 7, 2010
    8,719
    6,741
    270
    #1 EFA11, Jun 28, 2014
    Last edited by a moderator: Apr 20, 2017
    Code:
    compare-object -referenceobject $(get-childitem -path G:\httpdoc -recurse) -differenceobject $(get-childitem E:\ -recurse)
    This compares folder "G:\httpdoc" to "E:\"

    This is run and it finds no changes.
    Code:
    PS C:\Users\EFA\Desktop> C:\Users\EFA\Desktop\compare.ps1
    Now I created a new file on G:\httpdoc
    Code:
    PS C:\Users\EFA\Desktop> C:\Users\EFA\Desktop\compare.ps1
    
    InputObject                                                            SideIndicator                                                         
    -----------                                                            -------------                                                         
    NEW TEXT DOCUMENT.TXT                                                  <=                                                                    
    if I made a file on E: instead of G:\httpdoc it would show the indicator as =>.


    My question, is there a way to show the actual drive/folder e.g. G:\httpdoc instead of <= and E: instead of =>? I would like to occasionally have this run by someone else when I cannot remote in and over the phone it would be better for them to have a better verbal answer for me than less than equals or equals greater than (as I just heard on the phone lmao)
     
  2. Mr Jinje

    Mr Jinje MDL Expert

    Aug 19, 2009
    1,770
    1,101
    60
    #2 Mr Jinje, Jul 10, 2014
    Last edited by a moderator: Apr 20, 2017
    Not sure, haven't tried it lately, maybe add the pass-thru switch so we can see what kind of output you generate...

    On second thought look here, see the fullpath property, try that one.

    http://powershell.com/cs/blogs/tobias/archive/2009/01/09/tipps-amp-tricks-using-compare-object.aspx

    So you just need to figure out how to display the fullpath field instead of the sideindicator field, maybe knowing the right words to google for will help you write your own script. or play around with this example til you get stuck.

    http://stackoverflow.com/questions/6526441/comparing-folders-and-content-with-powershell

    Just a guess.

    Code:
    compare-object -referenceobject $(get-childitem -path G:\httpdoc -recurse) -differenceobject $(get-childitem E:\ -recurse) -Property Name, FullName, Length
     
  3. EFA11

    EFA11 Avatar Guru

    Oct 7, 2010
    8,719
    6,741
    270
    Thanks Mr. Jinje, I am closer to my goal. Your guess is close, I ran that as-is and it listed everything in both directories, but that's a good start to what I am looking for. I am prepping for work for tomorrow and Friday (late in the week surgeries), but will get on this during the weekend.

    Thank you for the response :D