Now, Out-HtmlView is just New-HTMLTable on steroids, and that means Compare and HighlightDifferences are both added as part of New-HTMLTable. Of course, that also means that it's available as part of Dashimo (Table -Compare -HighlightDifferences) or Emailimo (EmailTable -Compare -HighlightDifferences). Same feature working over different products and use cases.
Import-Module PSWriteHTML -Force
$Objects1 = @(
[PSCustomobject] @{ Test = 'My value'; Test1 = 'My value1' }
[PSCustomobject] @{ Test = 'My value 2'; Test1 = 'My value1' }
[PSCustomobject] @{ Test = 'My value 3'; Test1 = 'My value1' }
[PSCustomobject] @{ Test = 'My value 3'; Test2 = 'My value1', 'my value 3' }
)
$Objects2 = @(
Get-ADComputer -SearchBase 'OU=Domain Controllers,DC=ad,DC=evotec,DC=xyz' -Filter * #-Properties *
)
$Objects3 = @(
@{ Test = 'My value'; Test1 = 'My value1' }
@{ Test = 'My value 2'; Test1 = 'My value1' }
@{ Test = 'My value 3'; Test1 = 'My value1' }
@{ Test = 'My value 3'; Test2 = 'My value1', 'my value 3' }
)
New-HTML -TitleText $Title -UseCssLinks:$true -UseJavaScriptLinks:$true -FilePath $PSScriptRoot\Example15.html {
New-HTMLSection -HeaderText 'Comparing Objet with Highlighting Differences (PSCustomObject)' {
New-HTMLTable -DataTable $Objects1 -Compare -AllProperties -HighlightDifferences
}
New-HTMLSection -HeaderText 'Comparing Objet with Highlighting Differences (Domain Controllers)' {
New-HTMLTable -DataTable $Objects2 -Compare -AllProperties -HighlightDifferences
}
New-HTMLSection -HeaderText 'Comparing Objet with Highlighting Differences (Hashtables)' {
New-HTMLTable -DataTable $Objects3 -Compare -AllProperties -HighlightDifferences
}
} -ShowHTML
You can easily mix and match it with other functionality. Standard table data, next to table with comparison results, next to a chart. Your choice.
Import-Module PSWriteHTML -Force
$Objects1 = @(
[PSCustomobject] @{ Test = 'My value'; Test1 = 'My value1' }
[PSCustomobject] @{ Test = 'My value 2'; Test1 = 'My value1' }
[PSCustomobject] @{ Test = 'My value 3'; Test1 = 'My value1' }
[PSCustomobject] @{ Test = 'My value 3'; Test2 = 'My value1', 'my value 3' }
)
$Objects2 = @(
Get-ADComputer -SearchBase 'OU=Domain Controllers,DC=ad,DC=evotec,DC=xyz' -Filter * #-Properties *
)
$Objects3 = @(
@{ Test = 'My value'; Test1 = 'My value1' }
@{ Test = 'My value 2'; Test1 = 'My value1' }
@{ Test = 'My value 3'; Test1 = 'My value1' }
@{ Test = 'My value 3'; Test2 = 'My value1', 'my value 3' }
)
New-HTML -TitleText $Title -UseCssLinks:$true -UseJavaScriptLinks:$true -FilePath $PSScriptRoot\Example-Comparing02.html {
New-HTMLSection -HeaderText 'Comparing Objet with Highlighting Differences (PSCustomObject)' {
New-HTMLTable -DataTable $Objects1
New-HTMLTable -DataTable $Objects1 -Compare -AllProperties -HighlightDifferences
New-HTMLPanel {a
New-HTMLChart {
New-ChartBar -Name 'Test' -Value 1
New-ChartBar -Name 'Test1' -Value 2
New-ChartBar -Name 'Test2' -Value 3
}
}
}
New-HTMLSection -HeaderText 'Comparing Objet with Highlighting Differences (Domain Controllers)' {
New-HTMLTable -DataTable $Objects2
New-HTMLTable -DataTable $Objects2 -Compare -AllProperties -HighlightDifferences
}
New-HTMLSection -HeaderText 'Comparing Objet with Highlighting Differences (Hashtables)' {
New-HTMLTable -DataTable $Objects3
New-HTMLTable -DataTable $Objects3 -Compare -AllProperties -HighlightDifferences
}
} -ShowHTML
Nice right? I'm not sure if you've noticed, but there's one more parameter that I was using in New-HTMLTable, and that is AllProperties switch. This switch is available as part of Out-HtmlView as well. Its purpose is to allow all properties of all objects to be displayed. It's not always necessary, and it impacts speed, but it comes in handy. If you have ever worked with Active Directory, Exchange or Office 365, you probably noticed that not each object returned by those systems has all the same properties.
In my small domain following code returns
145,111,111,115,114,118,113,114,112,111,127,146,150,147,151,152,151,114,118,155,155,152,151,152,151,151,151,151,152,151,155,154,154,146,146,151,151,151,151,151,151,151,119,108,117,114,111,111,113
That shows that each object in Active Directory can have different properties. Why does it matter? It doesn't matter if you work with those objects in PowerShell and doing manipulation on those objects. Things get tricky if you try to display them with Format-Table, convert to CSV, Excel or HTML. You see, if you don't account for different properties per object (which is not that uncommon), most conversions are taking properties from 1st object and go with that for the rest of objects in an array losing all additional properties in the process. While Active Directory example is a bit extream because there's no way you would want to see 145 properties with Format-Table in PowerShell, but the following example can show you the problem I'm talking about.
As you can see, the fourth object lost Test2 property, and Format-Table skipped it. While it may not be something that happens very often, it does happen. And if you work with AD, Exchange or Office 365 it happens more often then you think. So what AllProperties switch does? Well, it tells New-HTMLTable to scan all objects first, take all of their properties, and start adding missing ones to the first object. That way, the first object in an Array suddenly has all unique properties from all objects, and we take it from there.
In the example above, you can see AllProperties switch made sure all properties are visible. There is a small performance impact because we first need to loop once and scan for all property names before we can process table, but for smaller datasets, this time should not be noticeable. This, of course, applies to EmailTable, Out-HtmlView.