Reputation: 25
I'm far from being an expert so I hope somebody can point me in the right direction, I'm writing a small script to gather inforamtion from an AD forest via Powershell and save everything in an HTML table-
My issue is with the table formatting to be more specific the table's header which is not acting as I would expect, here's my html to create/fromat the table
$htmlhead = "<html>
<style>
BODY{font-family: Verdana; font-size: 10pt;}
H1{font-size: 20px;}
H2{font-size: 18px;}
H3{font-size: 16px;}
TABLE{border: 1px solid black; border-collapse: collapse; font-size: 10pt;}
TH{border: 1px solid black; background: #dddddd; padding: 5px; color: #000000;}
TD{border: 1px solid black; padding: 5px; }
td.pass{background: #7FFF00;}
td.warn{background: #FFE600;}
td.fail{background: #FF0000; color: #ffffff;}
td.info{background: #85D4FF;}
</style>
<body>
<h1 align=""center"">Active Directory Inventory Information</h1>
<h3 align=""center"">Generated: $reportDate</h3>"
While a snippet of the PowerShell code is as follows
$adForest = Get-ADForest
$adForestInfo = New-Object -TypeName PsObject
$htmlBody += '<h3>Forest Details</h3>'
$adForestInfo | Add-Member -MemberType NoteProperty -Name 'Forest Name' -Value $($adForest.Name)
$adForestInfo | Add-Member -MemberType NoteProperty -Name 'Site' -Value $($adForest.Sites)
$htmlBody += $adForestInfo | ConvertTo-Html
If I use the above code all is good and I have a table with Forest and Forest Mode as a header but if I use only one property like this
$adForestInfo | Add-Member -MemberType NoteProperty -Name 'Forest Name' -Value $($adForest.Name)
I get an * instead of whatever property name I do assign via Add Member, I am not sure what I am doing wrong here and any help would really be aprpeciated.
Sorry if question is silly but I'm trying to learn so most probably I'm overlooking something really simple.
Upvotes: 0
Views: 1106
Reputation: 867
This appears to be a bug in ConvertTo-HTML. For objects with a single field it will display the asterisk *. I was unable to find a bug on Connect and it might be worth while to submit one.
You can get around this by actually specifying the property name in CovertTo-Html's -Property field:
$adForestInfo | ConvertTo-Html -Property "Forest Name"
You can read more in this question PSObject to ConvertTo-Html with header?
Upvotes: 2
Reputation: 7059
You're not doing anything wrong, that's just the default behavior: if there's only one property on all the objects, and you haven't explicitly asked for any specific properties, then it labels the column with an asterisk (indicating that the column represents "everything") instead of with the property name.
To get around this, you can explicitly specify which properties to display. Even if there's only one property, it will be labeled appropriately.
PS H:\> $adForestInfo | ConvertTo-HTML "Forest Name" -fragment
<table>
<colgroup>
<col/>
</colgroup>
<tr><th>Forest Name</th></tr>
<tr><td>actual property value here</td></tr>
</table>
Upvotes: 3