Can I use New-ChartEvent to filter timestamp values older than XX number of days? #460
-
My goal is to create a donut chart that consist of logons older than 30, 90, and 180 days that dynamically filters table data where the timestamp data is equal to true for one of the specific conditions (30, 90, or 180 days). Currently, I use a function to dynamically create chart data based on unique values and the count of each value. This is working well when my data returns say less than 20 unique values; however in the case of timestamps, it isn't very practical as almost all logon timestamps for say 500 results will be different. #function to get all unique values and count for donut chart
function Get-UniqueValueCount {
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[array]$List,
[Parameter(Mandatory)]
[string]$Key
)
# Create a hashtable to store unique values and their counts
$valueCount = @{}
# Loop through each item in the list
foreach ($item in $List) {
# Get the value for the specified key
$value = $item.$Key
# Handle cases where the value might be null or empty
if (-not [string]::IsNullOrEmpty($value)) {
# Increment the count for this value
if ($valueCount.ContainsKey($value)) {
$valueCount[$value]++
} else {
$valueCount[$value] = 1
}
}
}
# Convert the hashtable into an array of PSCustomObjects
$result = foreach ($key in $valueCount.Keys) {
[PSCustomObject]@{
Value = $key
Count = $valueCount[$key]
}
}
return $result
}
# Create list of computers
$reportList = [System.Collections.Generic.List[pscustomobject]]::new()
foreach ($WSUSComputer in $WSUSComputers) {
$result = [PSCustomObject]@{
'Name (WSUS)' = $WSUSComputerName
'LastSyncTime (WSUS)' = $WSUSComputer.LastSyncTime
'LastReportedStatusTime (WSUS)' = $WSUSComputer.LastReportedStatusTime
'UpdateNeeded (WSUS)' = $WSUSComputer.UpdateNeeded
'UpdateState (WSUS)' = $WSUSComputer.UpdateState
'PendingReboot (WSUS)' = $WSUSComputer.PendingReboot
'Model (WSUS)' = $WSUSComputer.Model
}
$reportList.Add($result)
}
# Pass list of computers in function to return unique values and total count of unique values
$LastSyncTime = Get-UniqueValueCount -List $reportList -Key 'LastSyncTime (WSUS)'
New-HTMLSection {
New-HTMLPanel {
New-HTMLChart -Title "LastSyncTime" {
foreach ($Time in $LastSyncTime) {
# Ensure that categories with zero count are not omitted
New-ChartDonut -Name $Time.Value -Value $Time.Count
}
# Enable chart event for filtering
New-ChartEvent -DataTableID 'Ooopsa' -ColumnID 4
}
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
So the way I do it, for my WSUS module but generally for when dealing with dates I create additional property which is translation to Days Once you have Days value which is 0 to X, you can easily create a count based on that value More then, Between and so on. While I didn't create charts yet for time for my own WSUS module, it shouldn't be too hard :-) Hope it helps? |
Beta Was this translation helpful? Give feedback.
So the way I do it, for my WSUS module but generally for when dealing with dates I create additional property which is translation to Days
Once you have Days value which is 0 to X, you can easily create a count based on that value More then, Between and so on. While I didn't create charts yet for time for my own WSUS module, it shouldn't be too hard :-)
Hope it helps?