DarkLite1
DarkLite1

Reputation: 14735

PowerShell ConvertTo-HTML list with only value

There's a custom object I created with a lot of key value pairs. Now I'm trying to create an HTML list of only the value and no name (header).

Example:

Get-ADnewUsers | Select-Object 'name' | ConvertTo-Html -Fragment -As List
<table>
<tr><td>*:</td><td>User1</td></tr>
<tr><td><hr></td></tr>
<tr><td>*:</td><td>User2</td></tr>
<tr><td><hr></td></tr>
<tr><td>*:</td><td>User3</td></tr>
</table>

Output:

*: User1
*: User2
*: User3

How can I get rid of the name column? Thank you for your help.

Get-ADnewUsers | ConvertTo-Html -Fragment -As List -Property 'Display name'

Output:

name: User1
name: User2
name: User3

But I would like it to generate only this:

User1
User2
User3

Upvotes: 0

Views: 7162

Answers (1)

Eric Eskildsen
Eric Eskildsen

Reputation: 4769

From the documentation:

The LIST value generates a two-column HTML table for each object that resembles the Windows PowerShell list format. The first column displays the property name; the second column displays the property value.

So it seems that behavior can't be modified with a different syntax.

What you could do, though, is strip the <td>name:</td> from each line of the result:

Get-ADnewUsers | ConvertTo-Html -Fragment -As List -Property 'name' | % { $_ -replace '<td>name:</td>', '' }

Upvotes: 4

Related Questions