Author Posts

August 29, 2017 at 8:24 am

Hi,
I am still dealing with counters.
Just found out that to run for long time with counters saved locally on could be space consuming indeed.
Trying to filter from saving information about counters with zero value.
I though about following:

(Get-counter -Counter ((get-counter -listset Processor).Paths  | Where-Object {
                                                    $_ -like "*" 
                                                    } ) -SampleInterval 2 -MaxSamples 1) 
                                                    | Where-Object {$_.CounterSamples.CookedValue -gt 0}

For some reason it is not working and I am still getting those with zero value.
It is strange, because when I am running same test on counters values only:

(Get-counter -Counter ((get-counter -listset Processor).Paths  | Where-Object {
                                                    $_ -like "*" 
                                                    } ) -SampleInterval 2 -MaxSamples 1).CounterSamples.CookedValue 
                                                    | Where-Object {$_ -gt 0}

It is working as I intended.

What I did wrong here?

Thanks.

August 29, 2017 at 11:37 am

Hi Pavel,

Get-Counter only seems to return one object, there is no way to filter this with a Where-Object (that I know of, or can think of at this time). Here's some code that will generate a list of results using the filter:

$Paths = (get-counter -listset Processor).Paths
$Results = @()
Get-counter -Counter $Paths -SampleInterval 2 -MaxSamples 1 | ForEach-Object {
    $Results += [pscustomobject]@{
        Timestamp = $_.Timestamp
        CounterSamples = $_.CounterSamples | Where-Object {
            $_.CookedValue -gt 0
        }
    }
}

August 29, 2017 at 11:45 am

Alternatively, if you don't care about the Timestamp you can achieve it with the following:

$Paths = (get-counter -listset Processor).Paths
(Get-Counter -Counter $Paths -SampleInterval 2 -MaxSamples 1).CounterSamples | Where-Object {
    $_.CookedValue -gt 0
}

August 29, 2017 at 11:47 am

Thanks.
Trying to implement it right now...