データテーブルをマージし、DataView
のToTable(bool distinct, params string[] columns)
メソッドを使用して、個別の値のみを除外します。例:
$dt1 = New-Object System.Data.DataTable
$dt1.Columns.Add("Make") > $null
$dt1.Columns.Add("Model") > $null
$dt1.Columns.Add("Year") > $null
$dt1.Rows.Add("Ford","Mustang","2010") > $null
$dt1.Rows.Add("Ford","Mustang","2011") > $null
$dt1.Rows.Add("VW","Golf","2016") > $null
$dt2 = New-Object System.Data.DataTable
$dt2.Columns.Add("Make") > $null
$dt2.Columns.Add("Model") > $null
$dt2.Columns.Add("Year") > $null
$dt2.Rows.Add("Ford","Fiesta","2010") > $null
$dt2.Rows.Add("Ford","Mustang","2011") > $null
$dt2.Rows.Add("VW","Golf","2016") > $null
#Load $dt2-values into $dt1
$dt1.Merge($dt2)
#Show merged table
$dt1
Make Model Year
---- ----- ----
Ford Mustang 2010
Ford Mustang 2011
VW Golf 2016
Ford Fiesta 2010
Ford Mustang 2011
VW Golf 2016
#Get distinct values only (distinct rows for make, model and year)
$dt1.DefaultView.ToTable($true,"Make","Model","Year")
Make Model Year
---- ----- ----
Ford Mustang 2010
Ford Mustang 2011
VW Golf 2016
Ford Fiesta 2010