Comparison of two arrays

Welcome Forums General PowerShell Q&A Comparison of two arrays

Viewing 2 reply threads
  • Author
    Posts
    • #258686
      Participant
      Topics: 4
      Replies: 8
      Points: 50
      Rank: Member

      Good morning everyone.
      I kindly need some help on this
      the comparison of two arrays.

      The scenario is this:

      I have 2 CSV files with this structure

      CSV n.1
      Name, Surname, Login, State
      CSV n.2
      Name, Surname, Login, State

      The code should do this:
      For each entry.Login of the CSV file n.1 must
      search for the corresponding entry.Login of the CSV file n.2

      If it matches, the State field must be checked.

      I try to explain it with an example
      CSV n.1
      Name, Surname, Login, State
      Karl, Malone, KarlM, Active
      Larry, Bird, LarryB, Active
      Dennis, Rodman, DennisR, Disabled

      CSV n.2
      Name, Surname, Login, State
      Dennis, Rodman, DennisR, Active
      Karl, Malone, KarlM, Active

      Output
      Karl, Malone, KarlM -> OK (because Active in each file)
      Larry, Bird, LarryB -> ERROR (because is missing in the second file)
      Dennis, Rodman, DennisR -> ERROR (because Disabled in first file but Enabled in the second file)

      Could someone give me some help on how to do it?

       

      Thank you very much

      Best regards

      Andrea

    • #258695
      Participant
      Topics: 16
      Replies: 1794
      Points: 3,300
      Helping Hand
      Rank: Community Hero

      Use Compare-Object:

      Output:

    • #258698
      Participant
      Topics: 12
      Replies: 541
      Points: 1,314
      Helping Hand
      Rank: Community Hero
Viewing 2 reply threads
  • You must be logged in to reply to this topic.