0
[Reflection.Assembly]::LoadFile("E:\oracle\product\11.2.0\ODP.NET\bin\2.x\Oracle.DataAccess.dll")

$constr = "User Id=system;Password=pass;Data Source=API"
$conn= New-Object Oracle.DataAccess.Client.OracleConnection($constr)
$conn.Open()
$sql="select name, user_id, password from dba_users"
$command = New-Object Oracle.DataAccess.Client.OracleCommand($sql,$conn)
$reader=$command.ExecuteReader()
$someArray = @()
#read all rows into a hash table
while ($reader.Read())
{
    $row = @{}
    for ($i = 0; $i -lt $reader.FieldCount; $i++)
    {
        $row[$reader.GetName($i)] = $reader.GetValue($i)
    }
    #convert hashtable into an array of PSObjects
    $someArray += New-Object PSObject -Property $row            
}

$conn.Close()
$someArray | Export-Csv C:\temp\someFile.csv

This query export result to CSV file.

I want to export it in HTML file. To make it more readable and stylish.

1 Answer 1

1

For exporting objects to HTML instead of CSV use ConvertTo-Html instead of Export-Csv and write the output to a file:

$style = @"
<style type='text/css'>
th {
  font-weight: bold;
  color: red;
}
</style>
"@

$someArray | ConvertTo-Html -Head $style | Out-File 'C:\temp\someFile.html'
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your answer. But i am looking for better solution. Like i want to make Row header of table in bold and Red color, values in black color in proper tabular form
@404 Did you actually bother reading the ConvertTo-Html documentation I linked to? The one that explains how to add headers to the generated HTML? Like, -Head '<style>th {font-weight:bold;color:red;}</style>' for instance?
This is how am i doing. add-content $report "<table width='100%'>" Add-Content $report "<tr bgcolor='IndianRed'>" Add-Content $report "<td width='12%' align='center'><B>Server Name</B></td>" Add-Content $report "<td width='63%' align='center'><B>Error Code</B></td>" Add-Content $report "<td width='12%' align='center'><B>Date-Time</B></td>" Add-Content $report "<td width='13%' align='center'><b>DB Instance</b></td>". Should i follow the same process.
@404 If you're asking if you should do all formatting via CSS: yes, you should.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.