Reputation: 127
I'm having a lot of trouble coming up with a way to properly add the data i want to a table I am looking for to a table. I'd like to then convert that table to HTML and send it via email. For the sake of the example, I am looking for things with a disconnected status but I am testing it using "connected" for now.
$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
The data i need to add to the table is:
$entry.name
$entry.'connection-status'
$entry.'engine-id'
I just cant figure this out - its driving me nuts! Any help is greatly appreciated! I keep trying different methods and it wont accept multiple values with the same key.
Upvotes: 0
Views: 68
Reputation: 36297
Right now you are passing an empty object to ConvertTo-Html
, so it produces nothing. You need to pass your objects to it in order to get the table you need.
$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
Upvotes: 1