locked
ConvertTo-HTML RRS feed

  • Question

  • Hi,

    I'm trying to get a dump of remote VMs and email the list of IntegrationService versions as HTML content. As soon as I run the content through convertto-html, I'm left with ... something... instead of the values I expect:

    $vmics2012=Get-ADComputer-filter{(name-like"*HV*") -and(enabled-eq$true) -and(OperatingSystemVersion-gt"6.1*")} -searchscopesubtree-searchbase"DC=corp,DC=company,DC=com"|

    ForEach-Object{invoke-command-ComputerName$_.name -ScriptBlock{Get-VM|ftComputerName,Name,IntegrationServicesVersion}}

    will give me an output that's nice to read:

    ComputerName                                                   Name                                                           IntegrationServicesVersion                                  
    ------------                                                   ----                                                           --------------------------                                  
    HVDR-01                                                        ADFSProxy02                                                    6.3.9600.16384                                              
    HVDR-01                                                        DCDR02                                                         6.3.9600.16384                                              
    HVDR-01                                                        SMTPDR01                                                       6.3.9600.16384                                              

    However, when I run:

    $vmics2012=Get-ADComputer-filter{(name-like"*HV*") -and(enabled-eq$true) -and(OperatingSystemVersion-gt"6.1*")} -searchscopesubtree-searchbase"DC=corp,DC=company,DC=com"|

    ForEach-Object{invoke-command-ComputerName$_.name -ScriptBlock{Get-VM|ftComputerName,Name,IntegrationServicesVersion}} |convertto-html

    I get:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <style>BODY{font-family: courier; font-size:11}</style>
    </head><body>
    <table>
    <colgroup><col/><col/><col/><col/><col/><col/><col/><col/><col/></colgroup>
    <tr><th>PSComputerName</th><th>RunspaceId</th><th>PSShowComputerName</th><th>ClassId2e4f51ef21dd47e99d3c952918aff9cd</th><th>pageHeaderEntry</th><th>pageFooterEntry</th><th>autosizeInfo</
    th><th>shapeInfo</th><th>groupingEntry</th></tr>
    <tr><td>HVDR-01</td><td>00ed8ef3-7cdf-421a-9d75-9e47eec01a2d</td><td>True</td><td>033ecb2bc07a4d43b5ef94ed5a35d280</td><td></td><td></td><td></td><td>Microsoft.PowerShell.Commands.Interna
    l.Format.TableHeaderInfo</td><td></td></tr>
    <tr><td>HVDR-01</td><td>00ed8ef3-7cdf-421a-9d75-9e47eec01a2d</td><td>True</td><td>9e210fe47d09416682b841769c78b8a3</td><td></td><td></td><td></td><td></td><td></td></tr>
    <tr><td>HVDR-01</td><td>00ed8ef3-7cdf-421a-9d75-9e47eec01a2d</td><td>True</td><td>27c87ef9bbda4f709f6b4002fa4af63c</td><td></td><td></td><td></td><td></td><td></td></tr>
    <tr><td>HVDR-01</td><td>00ed8ef3-7cdf-421a-9d75-9e47eec01a2d</td><td>True</td><td>27c87ef9bbda4f709f6b4002fa4af63c</td><td></td><td></td><td></td><td></td><td></td></tr>
    <tr><td>HVDR-01</td><td>00ed8ef3-7cdf-421a-9d75-9e47eec01a2d</td><td>True</td><td>27c87ef9bbda4f709f6b4002fa4af63c</td><td></td><td></td><td></td><td></td><td></td></tr>
    <tr><td>HVDR-01</td><td>00ed8ef3-7cdf-421a-9d75-9e47eec01a2d</td><td>True</td><td>4ec4f0187cb04f4cb6973460dfe252df</td><td></td><td></td><td></td><td></td><td></td></tr>
    <tr><td>HVDR-01</td><td>00ed8ef3-7cdf-421a-9d75-9e47eec01a2d</td><td>True</td><td>cf522b78d86c486691226b40aa69e95c</td><td></td><td></td><td></td><td></td><td></td></tr>
    <tr><td>HVDR-02</td><td>09cb4fae-60b1-490b-ba27-5a045cdebd4e</td><td>True</td><td>033ecb2bc07a4d43b5ef94ed5a35d280</td><td></td><td></td><td></td><td>Microsoft.PowerShell.Commands.Interna
    l.Format.TableHeaderInfo</td><td></td></tr>

    I'm not quite sure how I can retain my original data in an HTML table... any ideas?

    Thanks,

    Greg

    Monday, November 24, 2014 7:27 PM

Answers

  • Hi Greg,

    What are you expecting? Save the output as a .htm file and open it.


    EDIT: Also, don't use Format-* cmdlets, use Select-Object instead.

    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    • Edited by Mike Laughlin Monday, November 24, 2014 7:33 PM
    • Proposed as answer by tommymaynard Monday, November 24, 2014 7:51 PM
    • Marked as answer by Greg Beifuss Tuesday, November 25, 2014 6:12 PM
    Monday, November 24, 2014 7:31 PM
  • I knew what the problem was as soon as I started reading your post; Mike's edit is on it. Get away from using Format-* cmdlets unless it's a must. If you do use them, then never pipe from a Format-* cmdlet to another cmdlet unless you know it can interpret what the Format-* cmdlet does to your data. There's only a few cmdlets that you can pipe to if you've already piped to a Format-* cmldet, such as Out-Default or Out-File, for example.
    Edit: Typo.
    • Edited by tommymaynard Monday, November 24, 2014 7:59 PM
    • Marked as answer by AnnaWY Tuesday, December 9, 2014 5:44 AM
    Monday, November 24, 2014 7:51 PM

All replies

  • Hi Greg,

    What are you expecting? Save the output as a .htm file and open it.


    EDIT: Also, don't use Format-* cmdlets, use Select-Object instead.

    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    • Edited by Mike Laughlin Monday, November 24, 2014 7:33 PM
    • Proposed as answer by tommymaynard Monday, November 24, 2014 7:51 PM
    • Marked as answer by Greg Beifuss Tuesday, November 25, 2014 6:12 PM
    Monday, November 24, 2014 7:31 PM
  • Hi Mike,

    I'm expecting my table to show "ADFSProxy02" instead of "27c87ef9bbda4f709f6b4002fa4af63c" so that I can send it off in an HTML email:



    $messageParameters

    =@{                       

        Subject

    ="Hyper-V Integration Services Report "+$(Get-Date-format"MMMM d, yyyy")

        Body

    =$vmics2012


        From

    ="helpdesk@company.com"                     

        To

    ="greg@company.com"


        SmtpServer

    ="10.10.1.18" 

        Priority

    ="Normal"


        DNO

    ="onFailure, Delay"


    }  


    Send-MailMessage

    @messageParameters-BodyAsHtml

    Thanks,

    Greg

    Monday, November 24, 2014 7:35 PM
  • Hi Mike,

    I'm expecting my table to show "ADFSProxy02" instead of "27c87ef9bbda4f709f6b4002fa4af63c" so that I can send it off in an HTML email:

    <snip>

    Thanks,

    Greg

    Try the suggestion made in the edit of my first post.

    Don't retire TechNet! - (Don't give up yet - 13,085+ strong and growing)

    Monday, November 24, 2014 7:38 PM
  • I knew what the problem was as soon as I started reading your post; Mike's edit is on it. Get away from using Format-* cmdlets unless it's a must. If you do use them, then never pipe from a Format-* cmdlet to another cmdlet unless you know it can interpret what the Format-* cmdlet does to your data. There's only a few cmdlets that you can pipe to if you've already piped to a Format-* cmldet, such as Out-Default or Out-File, for example.
    Edit: Typo.
    • Edited by tommymaynard Monday, November 24, 2014 7:59 PM
    • Marked as answer by AnnaWY Tuesday, December 9, 2014 5:44 AM
    Monday, November 24, 2014 7:51 PM
  • Hi gentlemen,

    Thanks for the comments about not using format-table. I've removed that portion and I'm on the right track:

    $vmics2012=Get-ADComputer-filter{(name-like"*HV*") -and(enabled-eq$true) -and(OperatingSystemVersion-gt"6.1*")} -searchscopesubtree-searchbase"DC=corp,DC=company,DC=com"|


     

    ForEach-Object{invoke-command-ComputerName$_.name -ScriptBlock{Get-VM|select-objectComputerName,Name,IntegrationServicesVersion,integrationservicesstate}} |convertto-html-asTable-Head$style|out-string


     



    $msg

    =$msg+"<BR><BR><BR><BR>"+$vmics2012



    $messageParameters

    =@{                       

        Subject

    ="Hyper-V Integration Services Report "+$(Get-Date-format"MMMM d, yyyy")

        Body

    =$msg


        From

    ="helpdesk@company.com"                     

        To

    ="helpdesk@company.com"


        SmtpServer

    ="192.168.1.18" 

        Priority

    ="Normal"


        DNO

    ="onFailure, Delay"


    }  



    Send-MailMessage

    @messageParameters-BodyAsHtml

    Tuesday, November 25, 2014 6:13 PM