I need to remove the headers and spacing from a SQL dataset in Powershell so i can compare the result.
Using开发者_运维知识库 $res = $DataSet.Tables[0].rows | ft -HideTableHeaders removes the headers but leaves the spacing.
What is the best way of just showing the result
prptySwitch
-----------
False
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = "Select prptySwitch FROM dbo.PrptyLogSwitch"
$SqlCmd.Connection = $con
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$DataSet.Tables[0]
$res = $DataSet.Tables[0].rows
Thanks
If you actually want to compare, then why not just use Compare-Object
?
In any case, if you need just the property values without the header, then
Select-Object -ExpandProperty myProperty
will do exactly that.
$string1 = $DataSet1.GetXml()
$string2 = $DataSet2.GetXml()
$string1 -eq $string2
If you want to compare two DataSets, use their XML representation rather than the output of Format-Table.
精彩评论