0

Say I have collected these counters with Perfmon:

$MemCounters = (Get-Counter -ListSet Memory).Paths
$hello = Get-Counter -Counter $MemCounters -MaxSamples 2

Now I would like to display the result where I both can see the Counter values but also the timestamp for when the counter is from:

$hello.CounterSamples  
$hello.CounterSamples.Timestamp 

I would like column 1 to be $hello.CounterSamples.Timestamp and column 2 to be $hello.CounterSamples so that I later can import the data to SQL.

1 Answer 1

1

Since there are several counter samples per timestamp you have to extract them with a nested loop ...

$hello |
ForEach-Object {
    $CounterSampleList = $_.CounterSamples
    foreach ($CounterSample in $CounterSampleList) {
        [PSCustomObject]@{
            TimeStamp                = $_.TimeStamp
            CounterSamplePath        = $CounterSample.Path
            CounterSampleCookedValue = $CounterSample.CookedValue
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.