我需要比较Powershell数据表中的两列。结果,它应该创建3个新的数据表:
值是字符串值。
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
答案 0 :(得分: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