Watch-Heatmap.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function Watch-Heatmap
{
    <#
    .Synopsis
        Watches the performance heatmap
    .Description
        Watches the performance heatmap.
         
        Performance counters that are at dangerous levels are in dangerous colors.
    .Example
        Watch-Heatmap
    .Link
        Add-HeatmapCounter
    .Link
        Remove-HeatmapCounter
    .Link
        Get-HeatmapCounter
    #>

    param(
    # If set, continously watches the heatmap
    [switch]$Continuous,
    
    # If set, waits this period of time between each sample of the heatmap
    [Timespan]$WaitAfterGet = "0:0:0"
    )
    
    process {
        do {
            #region Get the values
            Get-HeatmapCounter -GetValue  |
                ForEach-Object {
                    $_.CounterSamples | 
                        ForEach-Object {
                            $_.pstypenames.clear()
                            $_.pstypenames.add('Heatmap')
                            $_
                                
                        }
                    
                }
            #endregion Get the values
            
            #region Wait if needed
            if ($Continuous -and $WaitAfterGet.TotalMilliseconds) {
                Start-Sleep -Milliseconds $WaitAfterGet.TotalMilliseconds
            }
            #endregion Wait if needed
        } while ($continuous)
        
        
    }
}