PSHTML Module + Getting System.Collections.Hashtable in Table

I’m facing issues when I export the content to a table with custom attributes.

It’s not showing the custom attribute values in the table. instead, it shows System.Collections.Hashtable. Is there any way to send the custom attributes in pshtml table

$Users = Get-ADUser -SearchBase $region -Filter { (passwordlastset -le $180Days) -and (passwordlastset -ne "0") -and (enabled -eq $true) } -Properties Displayname, SamAccountName, Passwordlastset -Server $server

foreach($User in $Users){
$User|ConvertTo-PSHTMLTable-properties @{Label=“Password Age”;Expression={((Get-Date)-($_.passwordlastset)).days }}, Displayname


ConvertTo-PSHTMLTable does not seem to support a Hashtable as input for its Property parameter.
You can easily solve this by using a Select/Object statement in the pipeline, before the ConvertTo-PSHTMLTable.


foreach($User in $Users){
$User | 
Select-Object -Property @{Label="Password Age";Expression={((Get-Date)-($_.passwordlastset)).days }}, Displayname |


Kind Regards



In your examples above, you actually create a HTML table, for every $User. I am unsure that that is what you guys actually really want.


This is how the cmdlet should actually work:


Import-module pshtml
Import-Module activeDirectory

$Users = Get-AdUser -Filter * -Properties Displayname, SamAccountName, Passwordlastset
$html = Html {
       #Pass the Object, and indicate to ConvertTo-PSHTMLTable which properties you want to have displayed.
       # If The -Properties is not specified, it will display all properties available on the object.
        ConvertTo-PSHTMLTable -Object $Users -Properties Displayname, SamAccountName, Passwordlastset

$html | out-file -Encoding utf8 -FilePath .\Woop.html
start .\Woop.html


On a general level, I would recommend to always ‘prepare’ an object to feed to ConvertTo-PSHTMLTable, use the -Object parameter, and filter with the -Properties.