Documentation: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.diagnostics/get-counter?view=powershell-5.1
Show all available counters, be careful, this seems to be language dependent
get-counter -listset * | Out-GridView
get-counter -listset "*Netzwerk*" | fl
get-counter -listset "*Netzwerk*" | % { $_.Counter }
Show all available processes
get-process | Out-GridView -PassThru
Get all counters of a teams process every ten seconds
$procCounter = get-counter -listset "Prozess" | % { $_.Counter }
get-counter $procCounter.replace("*", "ms-teams") -Continuous -SampleInterval 10
This is the most advanced example to create a flat table with the process counters every 10 seconds
$processName = "ms-teams"
$removeColumnPrefix = "\\desktop-cjokt0e\prozess(ms-teams)\"
get-counter $procCounter.replace("*", $processName) -Continuous -SampleInterval 10 | % { $o = [ordered]@{ "timestamp"=$_.Timestamp.ToString("yyyy-MM-ddTHH:mm:ssZ") }; $_.CounterSamples | % { $o.add( $_.Path.replace($removeColumnPrefix ,""), $_.CookedValue ) }; [pscustomobject]$o }
If you want to write it directly to a csv file, use it like this one
$procCounter = get-counter -listset "Prozess" | % { $_.Counter }
$processName = "ms-teams"
$removeColumnPrefix = "\\desktop-cjokt0e\prozess(ms-teams)\"
get-counter $procCounter.replace("*", $processName) -Continuous -SampleInterval 10 | % { $o = [ordered]@{ "timestamp"=$_.Timestamp.ToString("yyyy-MM-ddTHH:mm:ssZ") }; $_.CounterSamples | % { $o.add( $_.Path.replace($removeColumnPrefix ,""), $_.CookedValue ) }; [pscustomobject]$o } | Export-Csv -Path ".\teams-log.csv" -Encoding UTF8 -NoTypeInformation -Append
To run this job in the background (e.g. if you are running a remote rdp session), you can put this in a scriptblock and run it separately
$procCounter = get-counter -listset "Prozess" | % { $_.Counter }
$processName = "ms-teams"
$counter = $procCounter.replace("*", $processName)
$removeColumnPrefix = "\\desktop-cjokt0e\prozess(ms-teams)\" # this could also be done more dynamically
$logfile = "C:\Users\Florian\teams-log.csv" # better use an absolute path as the job is not starting at your users home directory
# The script loop the fill the logfile
$sc = [scriptblock]{
param ($counter, $removeColumnPrefix, $logfile)
Get-Counter $counter -Continuous -SampleInterval 10 | ForEach-Object {
$o = [ordered]@{
"timestamp"=$_.Timestamp.ToString("yyyy-MM-ddTHH:mm:ssZ")
}
$_.CounterSamples | ForEach-Object {
$o.add( $_.Path.replace($removeColumnPrefix ,""), $_.CookedValue )
}
[pscustomobject]$o
} | Export-Csv -Path $logfile -Encoding UTF8 -NoTypeInformation -Append
}
# Start a new background job
Start-Job -ScriptBlock $sc -ArgumentList $counter, $removeColumnPrefix, $logfile
# View the current status of jobs
Get-Job
# Stop the job with a specific id like
Stop-Job -Id 5
This could help if you need to rebuild the performance counters: https://learn.microsoft.com/en-us/troubleshoot/windows-server/performance/manually-rebuild-performance-counters