我遇到了很多麻烦,想方设法将我想要的数据正确添加到我正在寻找的表中。我想将该表转换为HTML并通过电子邮件发送。为了这个例子,我正在寻找断开状态的东西,但我现在正在使用“连接”进行测试。
$style = "<style>BODY{font-family: Arial; font-size: 10pt;}"
$style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
$style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
$style = $style + "TD{border: 1px solid black; padding: 5px; }"
$style = $style + "</style>"
$resp = Invoke-WebRequest -URI $uri -Body $login_request -ContentType 'text/xml' -Method post
[xml]$xmldata = $resp.content
if($xmldata.LoginResponse.success -eq '0'){
Write-Host 'ERROR: '$xmldata.LoginResponse.Failure.message -ForegroundColor Red
}
Else{
$SCRIPT:session_id = $xmldata.LoginResponse.'session-id'
Write-Host "Login Successful" -ForegroundColor Green
}
$disc_request = "<DiscoveryConnectionListingRequest session-id='$SCRIPT:session_id'/>"
$resp_disc = Invoke-WebRequest -URI $uri -Body $disc_request -ContentType 'text/xml' -Method post
[xml]$xmldata = $resp_disc.content
$xmldata.DiscoveryConnectionListingResponse.DiscoveryConnectionSummary
$table = @{}
foreach($entry in
$xmldata.DiscoveryConnectionListingResponse.DiscoveryConnectionSummary){
if($entry."connection-status" -eq "Connected") {
#add to table here
}
}
$html= New-Object psobject -Property $table | ConvertTo-Html
send-mailmessage -to "email" -from "email" -subject "Alert!" -BodyAsHtml "$html" -smtpserver server
我需要添加到表中的数据是:
$entry.name
$entry.'connection-status'
$entry.'engine-id'
我只是想不起来 - 它让我疯了!任何帮助是极大的赞赏!我一直在尝试不同的方法,并且不会使用相同的密钥接受多个值。
答案 0 :(得分:1)
现在你将一个空对象传递给ConvertTo-Html
,所以它什么也没有产生。您需要将对象传递给它才能获得所需的表格。
$HTML = $xmldata.DiscoveryConnectionListingResponse.DiscoveryConnectionSummary |
Where{$_.'connection-status' -eq 'connected'} |
ConvertTo-Html -As Table -Property Name,'Connection-Status','Engine-Id' -PreContent $Style
send-mailmessage -to "email" -from "email" -subject "Alert!" -BodyAsHtml -body $html -smtpserver server