locked
Compare 2 CSVs and Output New Members to 3rd CSV RRS feed

  • Question

  • Hi, 

    I have this 

    $test1=import-csv -path "FilteredMailboxes.csv"
    $test2=import-csv -path "ReportingUsers.csv"


    compare-object $test1 $test2 -property "mail" | export-csv 'test3.csv' -notypeinformation

    This is only getting me uncommon users between 2 CSVs. 

    I have an Exchange online script which update Group Membership every night. Currently I remove all members and add new members which takes a very long time. 

    To minimise time, I want to compare current members with new members and Output only new members. 

    Also if possible i want members which are not part of new membership be removed. 

    So compare 2 CSVs and:

    1. Output 3rd CSV with new members

    2. Output 4th CSV with members missing from new membership

    Thanks


    Hasan

    Wednesday, September 25, 2019 11:22 PM

Answers

  • As always read the ful lhelp carefully and completely. It will provide the answers and examples for all of your questions.

    help compare-object -online

    Add the parameter "IncludeEqual" to your command.

    Also you don't need to use quotes all over the place.

    $test1=import-csv -path FilteredMailboxes.csv
    $test2=import-csv -path ReportingUsers.csv
    
    compare-object $test1 $test2 -Property mail -IncludeEqual | 
    	Export-Csv test3.csv -NoTypeInformation
    


    \_(ツ)_/

    • Marked as answer by Exchanger-007 Thursday, September 26, 2019 1:00 PM
    Wednesday, September 25, 2019 11:32 PM

All replies

  • As always read the ful lhelp carefully and completely. It will provide the answers and examples for all of your questions.

    help compare-object -online

    Add the parameter "IncludeEqual" to your command.

    Also you don't need to use quotes all over the place.

    $test1=import-csv -path FilteredMailboxes.csv
    $test2=import-csv -path ReportingUsers.csv
    
    compare-object $test1 $test2 -Property mail -IncludeEqual | 
    	Export-Csv test3.csv -NoTypeInformation
    


    \_(ツ)_/

    • Marked as answer by Exchanger-007 Thursday, September 26, 2019 1:00 PM
    Wednesday, September 25, 2019 11:32 PM
  • Hi,

    Thanks for your question.

    You can try to use where-object to filter new members.

    Compare-Object $t1 $t2 -Property mail -IncludeEqual | Where-Object {$_.SideIndicator -eq "=>"}

    Best regards,

    Lee


    Just do it.

    Thursday, September 26, 2019 1:11 PM