Add-HeatmapCounter.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
function Add-HeatmapCounter
{
    <#
    .Synopsis
        Adds a Performance counter to the heatmap
    .Description
        Adds a Performance counter to the heatmap.
    .Example
        Add-HeatmapCounter '\Processor(*)\% Processor Time'
        Watch-Heatmap
    .Link
        Get-HeatmapCounter
    .Link
        Remove-HeatmapCounter
    .Link
        Watch-Heatmap
    #>

    param(
    # The name (short or full path) to the performance counter to add to the heatmap.
    # To see available performance counters, use Get-PercentagePerformanceCounter
    [Parameter(Mandatory=$true)]
    [string]
    $Name
    )
    
    
    process {
        #region check that it exists
        Write-Progress "Getting Counter value" "$Name"
        $counterSample = Get-Counter -Counter $name -ErrorAction Stop
        if (-not $counterSample) { return } 
        #endregion check that it exists
        
        #region add it
        $script:HeatMapCounters[$Name] = $name
        #endregion add it
    }
    
}