htmlpowershellfile-properties

Having an issue with writing correct information to htmlfile with powershell convertTo-html


This question has 2 parts: Ultimately I am trying to print out the data from the filedescription and originalfilename. The first and probably simple question is how do I get those on the same line? I am using PS G:\SysinternalsSuite> $values=@("filedescription", "originalfilename");foreach($V in $Values){(get-command g:\*\*\a*.exe).fileversioninfo.($v)} Windows Assessment and Deployment Kit - Windows 10 adksetup.exe Two lines, not one. I can edit it afterward, but...

The next issue is trying to output this information to a file: I am using (get-command g:\*\*\a*.exe).fileversioninfo.filedescription to return the prettified name of a folder of exe files (in this eg. I was working with SysInternalsSuite) Result:

PS G:\SysinternalsSuite> (get-command g:\*\*\a*.exe).fileversioninfo.filedescription
Windows Assessment and Deployment Kit - Windows 10

Worked beautifully... Then it went all wrong! My next idea was to put these values into an HTML file, so I did this:

<!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>
<title>HTML TABLE</title>
</head><body>
<table>
<colgroup><col/></colgroup>
<tr><th>*</th></tr>
<tr><td>50</td></tr>
</table>
</body></html>```

WTH are all these numbers??? Where's my data? Fine...
```PS G:\SysinternalsSuite> (get-command g:\*\*\a*.exe).fileversioninfo.filedescription | echo
Windows Assessment and Deployment Kit - Windows 10``` 
Perfect!
```PS G:\SysinternalsSuite> (get-command g:\*\*\a*.exe).fileversioninfo.filedescription | echo | convertTo-HTML
<!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>
<title>HTML TABLE</title>
</head><body>
<table>
<colgroup><col/></colgroup>
<tr><th>*</th></tr>
<tr><td>50</td></tr>
</table>
</body></html>
write GRRRR!!!!

Ok! What am I missing here?


Solution

  • ConvertTo-Html works by inspecting the properties of whatever object you pipe to it, and creates a table where each column corresponds to the property name.

    Since the [string] type only has one property - the Length property - that's what you get in the html table - a single column with the length of each input string.

    Instead, send an object where the description is the value of a property, then specify the list of properties you want in the table:

    (Get-Command g:\*\*\a*.exe).FileVersionInfo |ConvertTo-Html FileDescription