Need Help! SQL query to html RRS feed

  • Question

  • Hi Guys,

    I am running the following PowerShell script, that works fine is ISE, but unable to get the results to display correctly on an html page. I need some advice on how to get it done. The tables show up but no data is displayed in them.


    $a = "<style>"
    $a = $a + "BODY{background-color:peachpuff;}"
    $a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
    $a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
    $a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}"
    $a = $a + "</style>"

    $query = "SELECT secondary_server,last_restored_latency FROM msdb.dbo.log_shipping_monitor_secondary"

    foreach ($computer in get-content C:\test.txt)
    if ((Test-Connection $computer  -Count 1 -quiet)) 
    Write-Host  "$computer " -foreground "DarkBlue" 
    sqlcmd.exe  -E -S $computer  -Q $query | Select-Object secondary_server, last_restored_latency| ConvertTo-html -head $a | Out-File C:\scripts\test.html

    Sleep 2 

    } }

    Thanks in advance. 

    • Edited by RackHat Thursday, April 14, 2016 3:22 PM
    Thursday, April 14, 2016 3:21 PM


  • Remove the style sheet and add it in one item at a time until you get it to work.  Any one character out of place will invalidate the stype sheet.

    Here is how to more easily build a style sheet.

    <style type="text/css">
    	body {
    		background-color: peachpuff;
    	table {
    		border-width: 1px;
    		border-style: solid;
    		border-color: black;
    		border-collapse: collapse;
    	th {
    		border-width: 1px;
    		padding: 0px;
    		border-style: solid;
    		border-color: black;
    	td {
    		border-width: 1px;
    		padding: 0px;
    		border-style: solid;
    		border-color: black;

    All HTML tags are lowercase by requirement.

    You can comment out sections of a style sheet with /*   .....  */


    • Edited by jrv Thursday, April 14, 2016 9:12 PM
    • Proposed as answer by BASATI Friday, April 15, 2016 5:09 AM
    • Marked as answer by RackHat Friday, April 15, 2016 2:01 PM
    Thursday, April 14, 2016 9:10 PM