Closed ksl28 closed 3 years ago
It won't work the way you do it. First of all DateTimeSortingFormat
requires a string to be provided (you don't provide it) and so the table conditions are used as that string. Then your 2 top conditions have no value so they don't work at all.
$Table = @()
$obj = [PSCustomObject]@{
ServerName = "Server1"
Date = $(Get-Date -Format "dd-MM-yyyy HH:mm:ss")
DiskDefined = $false
IPDefined = $true
}
$obj = [PSCustomObject]@{
ServerName = "Server2"
Date = (Get-Date -Format "dd-MM-yyyy HH:mm:ss")
DiskDefined = $true
IPDefined = $true
}
$Table += $obj
New-HTML -Name "Report" {
New-HTMLTab -TabName 'ServerList' {
New-HTMLTable -DataTable $Table -DefaultSortIndex 10 -OrderMulti {
#New-HTMLTableCondition -Name 'ServerName' -Type string -BackgroundColor Gray
#New-HTMLTableCondition -Name 'Date' -Type string -BackgroundColor Gray
New-HTMLTableCondition -Name 'DiskDefined' -Type bool -Operator eq -Value $true -BackgroundColor Green -Inline
New-HTMLTableCondition -Name 'DiskDefined' -Type bool -Operator ne -Value $true -BackgroundColor red -Inline
New-HTMLTableCondition -Name 'IPDefined' -Type bool -Operator eq -Value $true -BackgroundColor Green -Inline
New-HTMLTableCondition -Name 'IPDefined' -Type bool -Operator ne -Value $true -BackgroundColor red -Inline
}
}
} -ShowHTML -FilePath $PSScriptRoot\mmmmm.html -Online
Please read: https://evotec.xyz/advanced-html-reporting-using-powershell/
DateTimeSorting can take strings for sorting dates in proper ways. Also, you don't have to push Date to string in your objects but can utilize the built-in functionality of PSWriteHTML which can do this for you.
Also for 30k objects I would go and enable DataStore JavaScript. Read the link it will help.
We have an huge list of objects (30000+), that consists of multiple columns such as ServerName, Date, Windows updates status, AV status, etc.
When publishing that in New-HTMLTable along with New-HTMLTableCondition, it always puts the False statements first, regards to the date. So i implemented the "-DateTimeSortingFormat", then it sorts by the Date column, but it removes all colors from the page.
It can be reproduced like this: $Table = @() $obj = [PSCustomObject]@{ ServerName = "Server1" Date = $(Get-date -Format "dd-MM-yyyy HH:mm:ss") DiskDefined = $false IPDefined = $true } Start-sleep -seconds 5 $obj = [PSCustomObject]@{ ServerName = "Server2" Date = (Get-date -Format "dd-MM-yyyy HH:mm:ss") DiskDefined = $true IPDefined = $true } $Table += $obj
New-HTML -Name "Report" { New-HTMLTab -TabName 'ServerList' { New-HTMLTable -DataTable $Table -DefaultSortIndex 10 -OrderMulti -DateTimeSortingFormat { New-HTMLTableCondition -Name 'ServerName' -Type string -BackgroundColor Gray New-HTMLTableCondition -Name 'Date' -Type string -BackgroundColor Gray New-HTMLTableCondition -Name 'DiskDefined' -Type bool -Operator eq -Value $true -BackgroundColor Green -Inline New-HTMLTableCondition -Name 'DiskDefined' -Type bool -Operator ne -Value $true -BackgroundColor red -Inline New-HTMLTableCondition -Name 'IPDefined' -Type bool -Operator eq -Value $true -BackgroundColor Green -Inline New-HTMLTableCondition -Name 'IPDefined' -Type bool -Operator ne -Value $true -BackgroundColor red -Inline } } } -ShowHTML
Is that intented to work this way?