The joy and pain of HTML

I'm trying to understand how Powershell interprets the data meets she ConvertTo-Html.  I used the front cmdlet with simple reports for snapshots, but now I want to start the conversion of a large number of scripts that are normally .txt to HTML files.  This is the first thing I try.

$custom = ' < style >

BODY {background-color: #999966 ;}}

TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse ;}}

TH {border-width: 1px; padding: 0px; border-style: solid; border-color: black ;}}

TD {border-width: 1px; padding: 0px; border-style: solid; border-color: black ;}}

< / style > '

Get-VMHost | foreach {"$(($_ |))"} Get-VMHostNetworkAdapter | where {$_.managementtrafficenabled - eq "true"} | {' (Sélectionnez-développez IP)) "+" ' t ' * 2 + "$($_.name)"} | ConvertTo-Html-head $custom - body ' addresses IP ESXi < H2 > < / H2 > ' | Out-file c:\Scripts\Hosts.htm

I formatted the above script to conform to how someone could enter data into their Windows hosts file, but I want to be able to take each line and put it online in a HTML document.

I tried this:

$HTMLhosts = get-VMHost | foreach {"$(($_ |))"} Get-VMHostNetworkAdapter | where {$_.managementtrafficenabled - eq "true"} | {' (Sélectionnez-développez IP)) "+" ' t ' * 2 + "$($_.name)"}

When I look at the variable above, I see the data that I want to, each line indicates the IP address and the name of the host on the same line, e.g.;   5.5.5.5 ESXihostname

If I look at $HTMLhosts [0], I see 1 line with the IP address and the host name.  If I use $HTMLhosts [0] | ConvertTo-html-fragment I get a random number

PS C:\Users > $HTMLhosts [0] | ConvertTo-Html-Fragment

< table >

< colgroup > < col / > < / colgroup >

< tr > < th > * < /th > < /tr >

< tr > < td > 41 < table > < /tr >

< /table >

I don't know if each object $ current _ must be converted somehow, and it is true that I am not an expert when it comes to html.  Of course I hope an answer for my current script can be converted to HTML, but overall, I want to understand how and why Powershell see data html and handle.

Any help is appreciated.

Hello, : DZ1-.

I would say the problem is to do with the way you mix strings and objects.  You should have better results if you stick with objects and then transfer those to the ConvertTo-Html cmdlet.  Something like:

$strCustomCSS = @''@

Get-VMHost |    ## select the properties to output    Select @{n="IP"; e={(Get-VMHostNetworkAdapter -VMHost $_ | where {$_.ManagementTrafficEnabled -eq $true}).IP}}, Name |    ## convert the objects to HTML, using the CSS    ConvertTo-Html -Head $strCustomCSS -Body '

ESXi IP addresses

' | Out-File c:\Scripts\Hosts.htm -Encoding Ascii

That worked for you?

Tags: VMware

Similar Questions

Maybe you are looking for

  • Download of El Capitan is never complete with interruption

    I tried to download El Capitan a dozen times now. Any brief interruption in the download because of power problems, internet issues results in 0% again restarts download. It doesn't seem to be an option to download the resume at all. Even if I stop i

  • Unable to connect to the app Photos on Apple TV

    I'm unable to connect to the application of Photos on Apple TV 4. I opened the app and it tells me to sign in iCloud. I go through the (difficult) process to type my username and password, he thinks for a while and then throws me back to the first sc

  • Limit how often a device has access to my wifi

    Is it possible to limit a MAC address can be on my network every day how long? I know how to activate time slots, but (1) I am more concerned that when total time (2) if I does not limit access to certain areas of the hour of the day, my router will

  • SP3 download size 0 KB...

    I have XP Home Edition and trying to download SP3.  Get SP3 download size 0 KB.  Need help please.  I read other messages and the moderator or tech always asking if there was already a trial of Norton on the pc version, Yes and also the full version

  • error messages

    I was always getting on these 3 startup messages: 1 runtime error 217 at 0043C5E4 2. tray Starter stopped working 3. Instant writing control center has stopped working.  I received the reply from TaurArian it might be the word Peerfece and Pinnacel D