Windows Vista Forums

Formating win32_bios output as HTML
  1. #1


    Richard Rosenheim Guest

    Formating win32_bios output as HTML

    I'm starting to experiment with PowerShell, and I'm trying to convert the
    output of this statement into a HTML page:



    get-wmiobject win32_bios | format-list *

    I have tried this:
    get-wmiobject win32_bios | format-list * | ConvertTo-HTML | Out-File
    C:\Test.htm

    but the resulting HTML page looks nothing like the text output generated by
    the first statement.

    Anyone have any suggestions as to how to get a HTML page with a two-column
    table similar to what the first statement generates?

    Thanks,

    Richard

      My System SpecsSystem Spec

  2. #2


    PaulChavez Guest

    RE: Formating win32_bios output as HTML

    Piping the output of format-list to convertto-html doesn't work as you're now
    converting formatting objects to html.

    ConvertTo-HTML gives you a table view, so you'll have to wrangle it a little
    to get a list view.



    "Richard Rosenheim" wrote:

    > I'm starting to experiment with PowerShell, and I'm trying to convert the
    > output of this statement into a HTML page:
    >
    > get-wmiobject win32_bios | format-list *
    >
    > I have tried this:
    > get-wmiobject win32_bios | format-list * | ConvertTo-HTML | Out-File
    > C:\Test.htm
    >
    > but the resulting HTML page looks nothing like the text output generated by
    > the first statement.
    >
    > Anyone have any suggestions as to how to get a HTML page with a two-column
    > table similar to what the first statement generates?
    >
    > Thanks,
    >
    > Richard

      My System SpecsSystem Spec

  3. #3


    PaulChavez Guest

    RE: Formating win32_bios output as HTML

    Here's a quick and dirty way to get it in list view. Uses get-member to get a
    list of properties on the wmi object then builds a new set of objects to pipe
    to convertto-html. It's kind of ugly but it works. Someone else might post a
    more straightforward solution.

    gwmi win32_bios |
    Tee-Object -var wmioutput |
    gm -membertype property |
    select name |
    %{$propname = $_.name;
    add-member -inputobj $_ -MemberType noteproperty -name Value -value `
    "$($wmioutput.$propname)" -PassThru } |
    convertto-html |
    out-file test.html


    -Paul

    "PaulChavez" wrote:

    > Piping the output of format-list to convertto-html doesn't work as you're now
    > converting formatting objects to html.
    >
    > ConvertTo-HTML gives you a table view, so you'll have to wrangle it a little
    > to get a list view.
    >
    >
    >
    > "Richard Rosenheim" wrote:
    >

    > > I'm starting to experiment with PowerShell, and I'm trying to convert the
    > > output of this statement into a HTML page:
    > >
    > > get-wmiobject win32_bios | format-list *
    > >
    > > I have tried this:
    > > get-wmiobject win32_bios | format-list * | ConvertTo-HTML | Out-File
    > > C:\Test.htm
    > >
    > > but the resulting HTML page looks nothing like the text output generated by
    > > the first statement.
    > >
    > > Anyone have any suggestions as to how to get a HTML page with a two-column
    > > table similar to what the first statement generates?
    > >
    > > Thanks,
    > >
    > > Richard

      My System SpecsSystem Spec

  4. #4


    Richard Rosenheim Guest

    RE: Formating win32_bios output as HTML

    Paul,

    Thank you for the example. It was very helpful and is what I'm looking for.
    Except that I'm not getting the actual values.

    In your example, you have a single quote after -value, which PowerShell
    gripes about. I tried removing it, which makes PowerShell happy, but doesn't
    get me the value property. I also tried adding a second single quote after
    the 2nd double quote, but that resulted in the string
    "$($wmioutput.$propname)" being included in the output.

    If I understanding what's happening, it would appear that
    "$($wmioutput.$propname)" is suppose to be returning the value of the
    property whose name is specified in $propname. But I can't see why it's not
    working.

    Richard




    "PaulChavez" wrote:

    > Here's a quick and dirty way to get it in list view. Uses get-member to get a
    > list of properties on the wmi object then builds a new set of objects to pipe
    > to convertto-html. It's kind of ugly but it works. Someone else might post a
    > more straightforward solution.
    >
    > gwmi win32_bios |
    > Tee-Object -var wmioutput |
    > gm -membertype property |
    > select name |
    > %{$propname = $_.name;
    > add-member -inputobj $_ -MemberType noteproperty -name Value -value `
    > "$($wmioutput.$propname)" -PassThru } |
    > convertto-html |
    > out-file test.html
    >
    >
    > -Paul
    >
    > "PaulChavez" wrote:
    >

    > > Piping the output of format-list to convertto-html doesn't work as you're now
    > > converting formatting objects to html.
    > >
    > > ConvertTo-HTML gives you a table view, so you'll have to wrangle it a little
    > > to get a list view.
    > >
    > >
    > >
    > > "Richard Rosenheim" wrote:
    > >

    > > > I'm starting to experiment with PowerShell, and I'm trying to convert the
    > > > output of this statement into a HTML page:
    > > >
    > > > get-wmiobject win32_bios | format-list *
    > > >
    > > > I have tried this:
    > > > get-wmiobject win32_bios | format-list * | ConvertTo-HTML | Out-File
    > > > C:\Test.htm
    > > >
    > > > but the resulting HTML page looks nothing like the text output generated by
    > > > the first statement.
    > > >
    > > > Anyone have any suggestions as to how to get a HTML page with a two-column
    > > > table similar to what the first statement generates?
    > > >
    > > > Thanks,
    > > >
    > > > Richard

      My System SpecsSystem Spec

  5. #5


    PaulChavez Guest

    RE: Formating win32_bios output as HTML

    Ah that's not a single quote, that's a backtick. I put that there to keep
    everything on it's own line. You can put the entire add-member command and
    all it's arguments on one line and it will work for you.

    Paul


    "Richard Rosenheim" wrote:

    > Paul,
    >
    > Thank you for the example. It was very helpful and is what I'm looking for.
    > Except that I'm not getting the actual values.
    >
    > In your example, you have a single quote after -value, which PowerShell
    > gripes about. I tried removing it, which makes PowerShell happy, but doesn't
    > get me the value property. I also tried adding a second single quote after
    > the 2nd double quote, but that resulted in the string
    > "$($wmioutput.$propname)" being included in the output.
    >
    > If I understanding what's happening, it would appear that
    > "$($wmioutput.$propname)" is suppose to be returning the value of the
    > property whose name is specified in $propname. But I can't see why it's not
    > working.

      My System SpecsSystem Spec

  6. #6


    Richard Rosenheim Guest

    RE: Formating win32_bios output as HTML

    Paul,

    I tried it again with both the backtick, and on one line. I'm still not
    getting any values in the 2nd column.

    Below is the resulting HTML output.

    Richard


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>HTML TABLE</title>
    </head><body>
    <table>
    <colgroup>
    <col>
    <col>
    </colgroup>
    <tr><th>Name</th><th>Value</th></tr>
    <tr><td>BiosCharacteristics</td><td></td></tr>
    <tr><td>BIOSVersion</td><td></td></tr>
    <tr><td>BuildNumber</td><td></td></tr>
    <tr><td>Caption</td><td></td></tr>
    <tr><td>CodeSet</td><td></td></tr>
    <tr><td>CurrentLanguage</td><td></td></tr>
    <tr><td>Description</td><td></td></tr>
    <tr><td>IdentificationCode</td><td></td></tr>
    <tr><td>InstallableLanguages</td><td></td></tr>
    <tr><td>InstallDate</td><td></td></tr>
    <tr><td>LanguageEdition</td><td></td></tr>
    <tr><td>ListOfLanguages</td><td></td></tr>
    <tr><td>Manufacturer</td><td></td></tr>
    <tr><td>Name</td><td></td></tr>
    <tr><td>OtherTargetOS</td><td></td></tr>
    <tr><td>PrimaryBIOS</td><td></td></tr>
    <tr><td>ReleaseDate</td><td></td></tr>
    <tr><td>SerialNumber</td><td></td></tr>
    <tr><td>SMBIOSBIOSVersion</td><td></td></tr>
    <tr><td>SMBIOSMajorVersion</td><td></td></tr>
    <tr><td>SMBIOSMinorVersion</td><td></td></tr>
    <tr><td>SMBIOSPresent</td><td></td></tr>
    <tr><td>SoftwareElementID</td><td></td></tr>
    <tr><td>SoftwareElementState</td><td></td></tr>
    <tr><td>Status</td><td></td></tr>
    <tr><td>TargetOperatingSystem</td><td></td></tr>
    <tr><td>Version</td><td></td></tr>
    <tr><td>__CLASS</td><td></td></tr>
    <tr><td>__DERIVATION</td><td></td></tr>
    <tr><td>__DYNASTY</td><td></td></tr>
    <tr><td>__GENUS</td><td></td></tr>
    <tr><td>__NAMESPACE</td><td></td></tr>
    <tr><td>__PATH</td><td></td></tr>
    <tr><td>__PROPERTY_COUNT</td><td></td></tr>
    <tr><td>__RELPATH</td><td></td></tr>
    <tr><td>__SERVER</td><td></td></tr>
    <tr><td>__SUPERCLASS</td><td></td></tr>
    </table></body></html>


      My System SpecsSystem Spec

  7. #7


    PaulChavez Guest

    RE: Formating win32_bios output as HTML

    Have you tried just copying and pasting directly out of my second post?

    I was just able to do that and get correct output.

    Here's the same method broken down into discrete steps so you can check each
    command for correct output.

    #gather output
    $wmioutput = gwmi win32_bios;
    $propnames = $wmioutput | gm -mem property | select name;
    #check both variables
    $wmioutput;
    $propnames;
    #try to use add-member
    $propnames | foreach {
    $propname = $_.name;
    add-member -inputobj $_ -membertype noteproperty `
    -name Value -value "$($wmioutput.$propname)"
    }
    #check $propnames to see if values stuck
    $propnames
    #assuming it's all ok then convert to html
    $propnames | convertto-html | out-file test.html

    Again, I used the backtick to put the add-member command on two lines
    because of the line wrapping when using the web form for posting here.

    good luck,
    Paul

    "Richard Rosenheim" wrote:

    > Paul,
    >
    > I tried it again with both the backtick, and on one line. I'm still not
    > getting any values in the 2nd column.
    >
    > Below is the resulting HTML output.
    >
    > Richard
    >
    >

      My System SpecsSystem Spec

  8. #8


    Richard Rosenheim Guest

    RE: Formating win32_bios output as HTML

    Paul,

    To answer your question, I did copy and paste the code from your 2nd post.

    The code you just provided does work. Yeah!!! Thank you.

    I've condensed the code down to this (which works):

    #gather output
    $wmioutput = gwmi win32_bios;
    $wmioutput | gm -mem property | select name |

    foreach {
    $propname = $_.name;
    add-member -inputobj $_ -membertype noteproperty `
    -name Value -value "$($wmioutput.$propname)" -PassThru
    } |
    convertto-html | out-file C:\test.html

    But, when I attempt to combine the first two lines (like you did in your
    first example), I again no longer get the 2nd column in the output:

    #gather output
    gwmi win32_bios | Tee-Object -var wmioutput |
    gm -mem property | select name |

    foreach {
    $propname = $_.name;
    add-member -inputobj $_ -membertype noteproperty `
    -name Value -value "$($wmioutput.$propname)" -PassThru
    } |
    convertto-html | out-file C:\test.html

    But, if I assign the output of Tee-Object to a variable which I then feed
    back into the pipe, it works, as follows:

    #gather output
    $tmpPipe = gwmi win32_bios | Tee-Object -var wmioutput
    $tmpPipe | gm -mem property | select name |

    foreach {
    $propname = $_.name;
    add-member -inputobj $_ -membertype noteproperty `
    -name Value -value "$($wmioutput.$propname)" -PassThru
    } |
    convertto-html | out-file C:\test.html

    At the moment, I'm baffled as to why would assigning the output of
    Tee-Object to a variable and the feeding it back into the pipe works, while
    piping the output of Tee-Object directly doesn't.

    Thanks again for all your assistance,

    Richard


    "PaulChavez" wrote:

    > Have you tried just copying and pasting directly out of my second post?
    >
    > I was just able to do that and get correct output.
    >
    > Here's the same method broken down into discrete steps so you can check each
    > command for correct output.
    >
    > #gather output
    > $wmioutput = gwmi win32_bios;
    > $propnames = $wmioutput | gm -mem property | select name;
    > #check both variables
    > $wmioutput;
    > $propnames;
    > #try to use add-member
    > $propnames | foreach {
    > $propname = $_.name;
    > add-member -inputobj $_ -membertype noteproperty `
    > -name Value -value "$($wmioutput.$propname)"
    > }
    > #check $propnames to see if values stuck
    > $propnames
    > #assuming it's all ok then convert to html
    > $propnames | convertto-html | out-file test.html
    >
    > Again, I used the backtick to put the add-member command on two lines
    > because of the line wrapping when using the web form for posting here.
    >
    > good luck,
    > Paul
    >
    > "Richard Rosenheim" wrote:
    >

    > > Paul,
    > >
    > > I tried it again with both the backtick, and on one line. I'm still not
    > > getting any values in the 2nd column.
    > >
    > > Below is the resulting HTML output.
    > >
    > > Richard
    > >
    > >

      My System SpecsSystem Spec

Formating win32_bios output as HTML problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
working on html objects using HTML DOM, VBscript Rama VB Script 3 18 Aug 2008
From one programmer to another WMIExplorer and Win32_Bios DiscoveryManagementPack Viewer might be worth downloading redwar VB Script 1 07 Jul 2008
get-help formating output BillN PowerShell 3 17 Jul 2007
Formatting HTML output possible? Jonathan Kalmes PowerShell 3 01 Feb 2007
Better HTML-ized output to file unicode/ascii thing cccstar PowerShell 1 20 Dec 2006