added function to build a list of intervals from hashtable

This commit is contained in:
Karl-Wilfried Zimmer 2024-02-08 23:54:24 +01:00
parent e8d0c0cd6c
commit 71eeccdd5a

View File

@ -103,3 +103,36 @@ function ProcessLogToHash {
) )
ProduceHashMap -Elements $(getElems -Path $Path) ProduceHashMap -Elements $(getElems -Path $Path)
} }
function buildIntervals {
param (
$hash
)
$array = @()
foreach ($key in $hash.Keys){
Write-Host $key
$list = $hash.$key
Write-Host $list
$lastState = $null
$lastTS = $null
foreach ($elem in $list){
Write-Host $elem
if (($elem.state -eq 'Started') -and ($null -eq $lastState)) {
$lastState=$elem.state
$lastTS=$elem.ts
}
if (($elem.state -ne 'Started') -and ($lastState -eq 'Started')) {
$array += @(New-Object psobject -Property @{
begining=$lastTS
ending=$elem.ts
state=$elem.state
vm=$key
})
$lastState=$null
$lastTS=$null
}
Write-Host "$array"
}
}
return $array
}