PSHTML Module + Getting System.Collections.Hashtable in Table

Welcome Forums General PowerShell Q&A PSHTML Module + Getting System.Collections.Hashtable in Table

Viewing 2 reply threads
  • Author
    Posts
    • #161303
      Participant
      Topics: 5
      Replies: 4
      Points: 21
      Rank: Member

      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
      }
    • #161328
      Participant
      Topics: 2
      Replies: 3
      Points: 17
      Rank: Member

      Hi

      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 |
      ConvertTo-PSHTMLTable 
      }

       

      Kind Regards

      HansO

    • #161382
      Participant
      Topics: 0
      Replies: 1
      Points: 8
      Rank: Member

      Hi,

      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 {
          Head{
          
          }
          Body{
             #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.

      Cheers

      #St├ęphane

       

Viewing 2 reply threads
  • The topic ‘PSHTML Module + Getting System.Collections.Hashtable in Table’ is closed to new replies.