我有一个使用数据适配器从MySQL数据库读取的脚本。表idInstance、IPAddress和auto id列中有三列。我只希望IdInstance和IPAddress显示在报表中,但是当我运行脚本并输出到表中时,我得到了7列,另外5列是RowError、RowState、table、ItemArray和HasErrors。我怎样才能只显示我想要的两列IdInstance和IpAddress列。请参见附加列的图像。而且控制台的输出是正确的,它只显示idinstance和ipaddress。所以它一定是构建HTML表的代码中的某个东西吗?

function Execute-MySQLQuery([string]$query) {
$command = New-Object MySql.Data.MySqlClient.MySqlCommand($query, $conn)
$dataAdapter = New-Object         MySql.Data.MySqlClient.MySqlDataAdapter($command)
$dataSet = New-Object System.Data.DataSet
$dataAdapter.Fill($dataSet, "data")
$command.Dispose()
return $dataSet.Tables["data"]
}

# So, to produce a table of results from a query...
$Header = @"
<style>
TABLE {border-width: 1px;border-style: solid;border-color:     black;border-collapse: collapse;}
TR:Nth-Child(Even) {Background-Color: #dddddd;}
TH {border-width: 1px;padding: 3px;border-style: solid;border-color:     black;background-color: #6495ED;}
TD {border-width: 1px;padding: 3px;border-style: solid;border-color:  black;}

</style>
<title>
Patch Report
</title>
"@
$Pre = "<h1>Patch Report </h1>"
$Pre += "<h2>These systmes are Not Running Patch Script</h2>"
$Post = "Run on "
$Post += Get-Date

$query = " SELECT prodinstances.Idinstance, prodinstances.IPAddress
FROM prodinstances
WHERE prodinstances.Idinstance
NOT IN (select prodwinupdates.ServersId FROM prodwinupdates) order by    IPAddress ASC"

$result = Execute-MySQLQuery $query
$strfound = ("Found " + $result.rows.count + " Systems that are not  currnetly running Patch Audit Script.")
$result  | Format-Table

          $emailSmtpServer = "mysmtpserver"
            $emailFrom = "[email protected]"
            $emailTo = "[email protected]"
            $emailSubject = $strfound
            $emailBody = $result | ConvertTo-HTML -Head $Header -PreContent $Pre -PostContent $Post | Out-String
    Send-MailMessage -To $emailTo -From $emailFrom -Subject $emailSubject -Body $emailBody -BodyAsHtml -SmtpServer $emailSmtpServe

html - Powershell表中的多余列-LMLPHP

最佳答案

指定希望ConvertTo-Html包含在-Property参数中的属性:

$emailBody = $result | ConvertTo-HTML -Property idInstance,IPAddress -Head $Header -PreContent $Pre -PostContent $Post

关于html - Powershell表中的多余列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38461510/

10-09 00:17