locked
convertto-html RRS feed

  • Question

  • I'm trying to convert a text file to a html using the above command..... Is not intuided as reading get-services for instance which you choose the field you want throught the select stament.

    What is exactly I'm doung wrong.......

    foreach ($rec in get-content C:\test.txt) {$($rec.Split(";")[0],$rec.Split(";")[1],$rec.Split(";")[2],$rec.Split(";")[3],$rec.Split(";")[4]) | ConvertTo-HTML -Title "Test" -head $format | Out-File c:\test.html}

    michael john ocasio

    Wednesday, January 23, 2013 3:43 PM

Answers

  • You're doubling the data in $format

    take a closer look

    $format += $format + something

    it means

    take $format variable and ADD (+=) to it $format (doubling value) and add something


    try adding -As Table to Convertto-HTML
    • Edited by Blindrood Thursday, January 24, 2013 12:40 PM
    • Marked as answer by mjocasio23 Thursday, January 24, 2013 10:08 PM
    Thursday, January 24, 2013 12:38 PM
  • -As <String>
        Determines whether the object is formatted as a table or a list. Valid values are TABLE and LIST. The default value
         is TABLE.

        The TABLE value generates an HTML table that resembles the Windows PowerShell table format. The header row displays
         the property names. Each table row represents an object and displays the object's values for each property.

        The LIST value generates a two-column HTML table for each object that resembles the Windows PowerShell list format.
         The first column displays the property name; the second column displays the property value.

    I now noticed from this help that TABLE is a default value so it doesn't change a thing :)

    • Marked as answer by mjocasio23 Saturday, January 26, 2013 6:39 AM
    Friday, January 25, 2013 7:36 AM

All replies

  • the first thing you are doing wrong is not giving enough information, like, show a sample of the input file, tell us what value the $format variable has, show any error messages, explain what is actually happening and how that differs from what you want to have happen.

    Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

    Wednesday, January 23, 2013 10:08 PM
  • Also note that:

       -Head <string[]>
           Specifies the content of the <HEAD> tag. The default is "<title>HTML TABLE</title>".  If you use the Head param
           eter, the Title parameter is ignored.


    Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

    Wednesday, January 23, 2013 10:10 PM
  • This is the data

    Data1;data2;data3           --------->delimiter by ;

    This is the code

    $format = “<style>”
    $format += "<body { font-family:Calibri;font-size:10pt;} ";
    $format+= $format + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;} "
    $format+= $format + "th { border-width:2px;padding: 1px;border-style: solid;border-color: black;background-color:#7c0f0f;color:white;} "
    $format+= $format + "td { border-width:2px;padding: 1px;border-style: solid;border-color: black;background-color:white;color:black; }>"
    $format += “</style>”

    $records = get-content C:\test.txt
    foreach ($record in $records) {
      $record.Split(";")[0],$record.Split(";")[1],$record.Split(";")[2],$record.Split(";")[3],$record.Split(";")[4] | ConvertTo-HTML -Title "Test" -head $format | set-content c:\test.html
    }

    If strip | ConvertTo-HTML -Title "Test" -head $format | set-content c:\test.html I see the data

    but if I added I get the follwoing

    *
    6
    66
    8
    7

    44

    if I iterate by object

    $records = get-content C:\test.txt
    $records | ForEach-Object {Add-Member -InputObject $_ -Type NoteProperty -Name Data -Value $_; $_} | ConvertTo-Html -Title "Test" -head $format -Property Data | out-file "c:\test.html"

    It generates the html file but one row/col table isntead of one and 4 columns according how I'm parsing the data from the input file....


    michael john ocasio

    Thursday, January 24, 2013 11:52 AM
  • You're doubling the data in $format

    take a closer look

    $format += $format + something

    it means

    take $format variable and ADD (+=) to it $format (doubling value) and add something


    try adding -As Table to Convertto-HTML
    • Edited by Blindrood Thursday, January 24, 2013 12:40 PM
    • Marked as answer by mjocasio23 Thursday, January 24, 2013 10:08 PM
    Thursday, January 24, 2013 12:38 PM
  • You're doubling the data in $format

    take a closer look

    $format += $format + something

    it means

    take $format variable and ADD (+=) to it $format (doubling value) and add something


    try adding -As Table to Convertto-HTML

    good catch, I didn't notice that at all...

    If that doesn't fix the problem, it could be that the issue is more of an HTML issue than a powershell one.


    Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

    Thursday, January 24, 2013 5:30 PM
  • Yes..... You are right......

    about the $format assigment..... What about the AS option to Table..... How that works that it could get convert to HTML


    michael john ocasio

    Thursday, January 24, 2013 10:05 PM
  • -As <String>
        Determines whether the object is formatted as a table or a list. Valid values are TABLE and LIST. The default value
         is TABLE.

        The TABLE value generates an HTML table that resembles the Windows PowerShell table format. The header row displays
         the property names. Each table row represents an object and displays the object's values for each property.

        The LIST value generates a two-column HTML table for each object that resembles the Windows PowerShell list format.
         The first column displays the property name; the second column displays the property value.

    I now noticed from this help that TABLE is a default value so it doesn't change a thing :)

    • Marked as answer by mjocasio23 Saturday, January 26, 2013 6:39 AM
    Friday, January 25, 2013 7:36 AM