0

I need to compare two columns in the datatable in Powershell. As result it should create 3 new datatables:

  • the same values in Column 1 and Column 2
  • only the values in Column 1
  • only the values in Column 2

Values are string values.

Column 1 | Column 2
---------|----------
Value 1  | Value 3
Value 2  | Value 4
Value 3  | Value 6
Value 4  | Value 7
Value 5  |

datatable_1:

Column 3 
---------
Value 3
value 4

datatable_2:

Column 1
---------
Value 1
Value 2
Value 5

datateble_3:

Column 2
---------
Value 6
Value 7
mattaspen
  • 5
  • 1
  • 4
    Can you please update your question with some code? As well as what you have tried so far and any specific issues/errors you are getting? – I.T Delinquent Jul 15 '19 at 15:54
  • Possible duplicate of [Comparing two arrays & get the values which are not common](https://stackoverflow.com/questions/6368386/comparing-two-arrays-get-the-values-which-are-not-common) – iRon Jul 15 '19 at 16:14

1 Answers1

0

$Table = ConvertFrom-SourceTable '

Column 1 | Column 2
---------|----------
Value 1  | Value 3
Value 2  | Value 4
Value 3  | Value 6
Value 4  | Value 7
Value 5  |'

PS C:\> $Table | Select 'Column 1' | Where {$Table.'Column 2' -Contains $_.'Column 1'}

Column 1
--------
Value 3
Value 4


PS C:\> $Table | Select 'Column 1' | Where {$Table.'Column 2' -NotContains $_.'Column 1'}

Column 1
--------
Value 1
Value 2
Value 5


PS C:\> $Table | Select 'Column 2' | Where {$Table.'Column 1' -NotContains $_.'Column 2'}

Column 2
--------
Value 6
Value 7
iRon
  • 20,463
  • 10
  • 53
  • 79