Server Fault Asked by Jonathan Davies on February 9, 2021
I’m trying to run the following command and return it through HTML:
[System.Net.Dns]::GetHostByName($env:computerName).Hostname
This returns my computer name, however if I try to export it to HTML, using ConvertTo-HTML I retrieve an arbatory value of "* 27":
[System.Net.Dns]::GetHostByName($env:computerName).Hostname | ConvertTo-Html
Result:
<!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>27</td></tr>
</table>
</body></html>
I’d expect the result to be the output of the first command, which is my actual PC name.
Exactly as documented: property supplied by the pipeline is InputObject
:
-InputObject
… To create a table of the individual objects, use the pipeline operator to pipe the objects to
ConvertTo-Html
.
When you submit multiple objects to ConvertTo-Html
, PowerShell creates the table (or list) based on the properties of the first object that you submit.
You piped a string; hence, the table shows the only string property, its length (the number 27 in your output).
Try
[System.Net.Dns]::GetHostByName($env:computerName) |
ConvertTo-HTML -Property HostName
Answered by JosefZ on February 9, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP