Get Counter - PowerShell
Overview
Get-Counter retrieves performance counter data from the local computer or remote computers. It enables monitoring and analysis of system and application performance.
Syntax
Get-Counter [-ListSet <String>] [-Credential <PSCredential>] [-ComputerName <String>]
[-SampleInterval <TimeSpan>] [-MaxSamples <Int32>] [-Format <String>]
[-Filter <String>] [-IncludeInstanceInfo] [-ErrorAction <ActionPreference>]
[-WarningAction <ActionPreference>]
Options/Flags
| Option | Description | Default |
|—|—|—|
| -ListSet | Specifies the performance counter category and object to retrieve. | |
| -Credential | Credential to use when connecting to remote computers. | |
| -ComputerName | Computer to retrieve performance data from. | Local computer |
| -SampleInterval | Time interval between samples. | 1 second |
| -MaxSamples | Maximum number of samples to collect. | Unlimited |
| -Format | Output format for results. | Text |
| -Filter | Filter to apply to the performance counter objects. | |
| -IncludeInstanceInfo | Include instance information in the results. | False |
| -ErrorAction | Action to take on errors. | Stop |
| -WarningAction | Action to take on warnings. | Continue |
Examples
Simple Usage:
Get-Counter -ListSet "Processor" -ComputerName "RemoteComputer"
Collect Samples over Time:
Get-Counter -ListSet "Memory\Available MBytes" -MaxSamples 100 -SampleInterval 1
Filter by Instance Name:
Get-Counter -ListSet "LogicalDisk" -Filter "InstanceName = '_Total'"
Format Results as CSV:
Get-Counter -ListSet "System\Processor Queue Length" | Format-List -Property Value | Export-Csv -Path "performance.csv"
Common Issues
- Permission Denied: Ensure you have sufficient permissions to access performance counters on the target computer.
- Counter Not Found: Verify that the specified counter exists on the target computer.
- High Memory Usage: Collecting large numbers of samples can consume excessive memory. Adjust the
-MaxSamples
value as needed.
Integration
- Combine with New-PerformanceCounter: Create a new performance counter using data retrieved by
Get-Counter
. - Use with Invoke-Command: Execute
Get-Counter
remotely on multiple computers. - Log Performance Data: Write performance data to a file or database for long-term analysis.
Related Commands
- Get-CounterSet
- New-PerformanceCounter
- Remove-PerformanceCounter