locked
Comparing Data within 2 Text Files RRS feed

  • Question

  • Hi Guys,

    Im looking for some guidance.

    I have 2 text files. neither is in any particular order

    For example:

    FILE1                              FILE2

    ERIC F                            JOHN B

    JOHN B                           CHRIS T

    JOE B                             ERIC F

    CHRIS T

    Im looking for a way to compare the data within these files and retrieve the names of FILE 1 that do not exist in FILE2.

    I've attempted several times at using Compare function without any luck, I think im getting confused somewhere along the line.

    So Far I have this:

    #######COMPARE FILE CONTENTS#######

    $strSFB

    =Get-Content"C:\PS_SCRIPTS\0365_SKYPE_EXTERNAL_USERS\SFBUSERS.txt"


    $strINPLACE

    =Get-Content"C:\PS_SCRIPTS\0365_SKYPE_EXTERNAL_USERS\SFBAUDIT.txt"

    Compare-Object$strSFB$strINPLACE

    However, the results return each line with <= as well as =>

    I've tried sorting the files alphabetically, however some reason one of the files wont Sort properly. So before going further I want to see if anyone can supply a fresh idea...

    For a bit of background, the data in the 'FILE1' is a list of active Skype For business users, 'FILE2' is a list of SourceMailboxes within an In-Place hold group. The idea is to gather a list of Skype user that are not in the In-Place Hold group.

    Thanks

    Mike

     

    Thursday, August 17, 2017 10:42 AM

All replies

  • Please do not post colored code. Instead you should use the code posting tool located at the edit bar when you create a post.

    $StrFSB = 'ERIC F','JOHN B','JOE B','CHRIS T'
    $StrInPLace =  'JOHN B','CHRIS T', 'ERIC F'
    
    Compare-Object -ReferenceObject $StrFSB -DifferenceObject $StrInPLace -PassThru
    

    The result in this case is JOE B.

    Is it hat what you want?


    Grüße - Best regards

    PS:> (79,108,97,102|%{[char]$_})-join''

    • Proposed as answer by I.T Delinquent Thursday, August 17, 2017 11:25 AM
    Thursday, August 17, 2017 11:22 AM