Get-Counter

Get performance counter data from local and remote computers.

Syntax
      Get-Counter [-Counter] string[] [-ComputerName string[]] [-Continuous]
        [-MaxSamples Int64] [-SampleInterval int] [CommonParameters]

      Get-Counter -ListSet string[] [-ComputerName string[]] [CommonParameters]

Key:
   -ComputerName string[]
       Get data from the specified computer(s).
       Type the NetBIOS name, an Internet Protocol (IP) address, or fully qualified domain names.
       The default value is the local computer.

       Note:  Get-Counter does not rely on PowerShell remoting.

   -Continuous
       Get samples continuously until you press CTRL+C.
       By default, Get-Counter gets only one counter sample.
       Use -SampleInterval to set the interval for continuous sampling.

   -Counter string[]
       Get data from the specified performance counters.
       Enter one or more counter paths. Wildcards are permitted only in the Instance value.
       You can also pipe counter path strings to Get-Counter. 

       Each counter path has the following format:
               "[\\<ComputerName>]\<CounterSet>(<Instance>)\<CounterName>" 

       For example: 
                "\\Server01\Processor(2)\% User Time".  

       The ComputerName element is optional. If you omit it, Get-Counter uses the value of -ComputerName.

       Note:  To get correctly formatted counter paths, use -ListSet to get a performance counter set.

       The Paths and PathsWithInstances properties of each performance counter set contain
       the individual counter paths formatted as a string. You can save the counter path strings
       in a variable or pipe the string directly to another Get-Counter command. See the examples.

   -ListSet string[]
       Get the specified performance counter sets on the computers.
       Enter the names of the counter sets. Wildcards are permitted.
       You can also pipe counter set names to Get-Counter.

   -MaxSamples Int64
       The number of samples to get from each counter.
       The default is 1 sample. To get samples continuously (no max sample size), use -Continuous.

       To collect a very large data set, consider running a Get-Counter command as a PowerShell background job.
       For more information, see about_Jobs and Start-Job.

   -SampleInterval int
       The time between samples in seconds.
       The minimum value and the default value are 1 second.

   CommonParameters:
       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
       -OutBuffer -OutVariable.

Get-Counter gets live, real-time performance counter data directly from a local or remote Windows computer. Without parameters, Get-Counter will get counter data for a set of system counters.

Examples

Get all of the counter sets on the local computer. Run this command with "Run as administrator" to see all counter sets as many are protected by access control lists (ACLs.)

PS C:> get-counter -ListSet *

Get the current "% Processor Time" combined values for all processors on the local computer. Collect data every 2 seconds until 10 sample values are collected.

PS C:> get-counter -Counter "\Processor(_Total)\% Processor Time" -SampleInterval 2 -MaxSamples 10

Get a sorted list of all the counter set names:

PS C:> get-counter -listset * | sort-object countersetname | format-table countersetname

Get the correctly formatted path names of the performance counters in the Memory counter set: (this can also be done with .pathswithinstances)

PS C:> (get-counter -listset memory).paths

Get the correctly formatted path names that include "cache":

PS C:> (get-counter -listset memory).paths | where {$_ -like "*cache*"}

Save the Disk Reads/sec counter path in the $diskreads variable..

PS C:> $diskreads = "\LogicalDisk(C:)\Disk Reads/sec"

Pipe the counter path (in $diskreads) to Get-Counter:

PS C:> $diskreads | get-counter -computer Server64, Server65 -maxsamples 10

Get a list of 50 randomly selected servers from the Servers.txt file and store in a variable:

PS C:> $servers = get-random (get-content servers.txt) -count 50

Save a counter path in the $Counter variable and then get the counter values for all the servers.

PS C:> $counter = "\Processor(*)\% DPC Time"
PS C:> get-counter -Counter $counter -computername $servers

Get a single value for all of the performance counters in the memory counter set on the local computer. First get the counter paths and then get the counter data for each counter:

PS C:> $memCounters = (get-counter -list memory).paths
PS C:> get-counter -counter $memCounters

The properties of the CounterSamples object can be used to examine, select, sort, and group data:

PS C:> $counter = "\\SERVER64\Process(Idle)\% Processor Time"
PS C:> $data = get-counter $counter
PS C:> $data.countersamples | format-list -property *

Run a Get-Counter command as background job.

PS C:> $counters = "\LogicalDisk(_Total)\% Free Space"
PS C:> start-job -scriptblock {get-counter -counter $counters -maxsamples 1000)

Find the '% free disk space' on 50 computers selected randomly from Servers.txt

PS C:> get-counter -computername (get-random servers.txt -count 50) -counter "\LogicalDisk(*)\% Free Space"

“I was going to thrash them within an inch of their lives, but I didn't have a tape measure” ~ Groucho Marx

Related:

Export-Counter - Export Performance Counter data to log files
Import-Counter - Import performance counter log files


© Copyright SS64.com 1999-2013
Some rights reserved