When working with Windows Performance Monitor (Perfmon) and logman commands, you often need to reference exact counter names in your configuration files. Manually copying these from the GUI is tedious, especially when dealing with dozens of counters across multiple categories.
The most efficient method is using PowerShell to query available counters. Here's a script that exports all counters to a text file:
# Get all performance counter categories
$categories = [System.Diagnostics.PerformanceCounterCategory]::GetCategories()
# Output to text file
$outputFile = "C:\temp\perfcounters.txt"
$counters = foreach ($category in $categories) {
if ($category.CategoryType -eq "MultiInstance") {
$instanceNames = $category.GetInstanceNames()
foreach ($instance in $instanceNames) {
$category.GetCounters($instance) | Select-Object CounterName, InstanceName, CategoryName
}
} else {
$category.GetCounters() | Select-Object CounterName, InstanceName, CategoryName
}
}
$counters | Export-Csv -Path $outputFile -NoTypeInformation -Encoding UTF8
For a simpler approach, you can use the built-in TypePerf command to list counters:
typeperf -q > counters_list.txt
Once you have your counter list, you'll need to format it for logman. Here's an example of proper logman counter syntax:
logman create counter MyPerfLog -o "C:\perflogs\mylog.blg" -f bin -v mmddhhmm -c "\Processor(_Total)\% Processor Time" "\Memory\Available MBytes"
To extract just the counters you need, modify the PowerShell script with a filter:
# Filter for processor-related counters only
$counters | Where-Object { $_.CategoryName -like "*Processor*" } | Export-Csv -Path "processor_counters.txt" -NoTypeInformation
You can also query counters from remote machines by adding the -ComputerName parameter:
Get-Counter -ListSet * -ComputerName Server01 | Select-Object CounterSetName
When setting up performance monitoring with logman
, manually collecting counter paths through the PerfMon GUI is tedious. The interface doesn't provide direct export functionality, forcing users to copy-paste individual counters - a nightmare when dealing with dozens of counters.
The easiest method is using PowerShell to programmatically extract counters. Here's a comprehensive script that outputs all available counters to a text file:
# Get all performance counter categories
$categories = [System.Diagnostics.PerformanceCounterCategory]::GetCategories()
# Output file path
$outputFile = "C:\temp\perf_counters.txt"
# Clear existing file
if (Test-Path $outputFile) { Remove-Item $outputFile }
foreach ($category in $categories) {
try {
# Write category name
Add-Content -Path $outputFile -Value "[$($category.CategoryName)]"
# Get instance names if applicable
if ($category.CategoryType -eq "MultiInstance") {
$instances = $category.GetInstanceNames()
foreach ($instance in $instances) {
$counters = $category.GetCounters($instance)
foreach ($counter in $counters) {
Add-Content -Path $outputFile -Value "$($counter.CounterName) ($instance)"
}
}
} else {
# Single instance counters
$counters = $category.GetCounters()
foreach ($counter in $counters) {
Add-Content -Path $outputFile -Value $counter.CounterName
}
}
Add-Content -Path $outputFile -Value ""
} catch {
Write-Warning "Error processing category $($category.CategoryName): $_"
}
}
Write-Host "All performance counters exported to $outputFile"
For more targeted exports, modify the script to filter counters:
# Export only processor-related counters
$processorCounters = $categories | Where-Object { $_.CategoryName -like "*Processor*" }
$processorCounters | ForEach-Object {
$_ | Get-Counter -Counter $_.GetCounters().CounterName |
Export-Counter -Path "C:\temp\processor_counters.csv" -FileFormat CSV
}
To create a logman configuration file directly, use this format conversion:
Get-Counter -ListSet * | ForEach-Object {
$setName = $_.CounterSetName
$_.Paths | ForEach-Object {
""$($_.Replace('*','_Total'))"" | Out-File "logman_config.txt" -Append
}
}
The built-in typeperf
command can also list counters:
typeperf -q > all_counters.txt
For a specific counter set:
typeperf -q -s SERVERNAME -o "Processor Information" > cpu_counters.txt
When building your logman configuration:
- Always use English counter names (even on localized systems)
- Include both instance-specific and _Total counters where applicable
- Standardize on either forward or backward slashes in paths
- Consider using wildcards for dynamic instances (e.g., "Process(*)\% Processor Time")