Powershell htmlout not working. Get sql result in html form.

Dear experts, this code below is not working,
I think $htmlout = select-object count| convertto-html -head $a
is not really work as thought, I want to show the sqlQuery result in a html file and I use: "select-object count" Now Im not sure if i used it right. the result is blank. Nothing. Anyone can help me help me solve this?


$SQLServer = "SQL01\Trans"
$SQLDBName = "Runtime"

$SqlQuery = "

SELECT count(*)
FROM [Prod].[Data].[IncomingUpdate_fd]
WHERE InsertTime >= DATEADD(day,-10, getdate())
)As Incoming Prod,
SELECT count(*)
FROM [Prod].[Data].[IncomingUpdate_fd]
WHERE InsertTime >= DATEADD(day,-10, getdate()) AND IsProcessed = 'P'
)As Incoming Processed,
SELECT count(*)
FROM [Prod].[Data].[IncomingUpdate_fd]
WHERE InsertTime >= DATEADD(day,-10, getdate()) AND IsProcessed is null
)As Not Processed


$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; user id = XXXX; password = XXXX"

$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SqlConnection

$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd

$DataSet = New-Object System.Data.DataSet

$a = "<style>"
$a = $a + "BODY{background-color:white;font-family:verdana;font-size:12px;}"
$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;padding:3px}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;padding:3px}"
$a = $a + "</style>"

$htmlout = select-object count| convertto-html -head $a
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dustin SaundersDirector of OperationsCommented:
So, your issue is that you are using Select-Object on nothing, then converting that to html.

So what you would want is something like this to select the properties:

$htmlout = $DataSet | ConvertTo-Html -Head $a -Property 'Incoming Prod','Incoming Processed','Not Processed'

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WeTiAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.