Guy recommends :
Free Permissions
Analyzer Tool

Solarwinds Free Download of Permissions Analyzer

 

View the effective permissions for a folder or shared drive. Free download try it now!


PowerShell Get-Counter Cmdlet

 PowerShell Get-Counter

PowerShell's Get-Counter is an alternative technique to employing Perfmon.  Normally it's easy to be enthusiastic about PowerShell, but in the case of Get-Counter, I would not attempt to create scripts until I had a working knowledge of Performance Monitoring.

Topics for PowerShell Get-Counter

 ♣

Our Mission

Success or failure of Get-Counter missions depends on having clear objectives.  You need a working knowledge of Performance Monitoring because you need to make sense of strings such as:

"\Memory\Available Bytes"
"\Processor(_total)\% processor time"
"\LogicalDisk(_Total)\% Free Space"

Once you beg, borrow or copy the correct Performance counter, then preceding with Get-Counter is the easy part.  However, all is not plain sailing, you need to be able to interpret the data, and probably save to file (Out-File).

Example 1: Get-Counter -ListSet *

Pre-requisites.  You must log on as Administrator.

# PowerShell Get-Counter -ListSet
Clear-Host
Get-Counter -ListSet mem*

Note 1a:  You really do need the full parameter name -ListSet.  PowerShell has lots of cmdlets that use just -List, but Get-Counter is NOT one of them.

Note 1b:  Pure -ListSet * returns so many CounterSetNames that is why I filtered the command to display just the memory counters.  Also note that -ListSet on its own does not work, furthermore you need that space between -ListSet and the * wildcard.

Example 2: Real-life Task For Get-Counter

Enough doom and gloom.  If I have not put you off, then you must be keen to master Get-Counter, so here is a working example to monitor the processor.

# PowerShell Get-Counter Processor Example
Get-Counter -counter "\processor(_total)\% processor time" -continuous

Example 2a: Configure -SampleInterval Also, Save to File

# PowerShell Get-Counter Processor Example
Get-Counter -counter "\processor(_total)\% processor time" `
-SampleInterval 10 -MaxSamples 5 # | Out-File "C:\logs\processor.ps1"

Note 2a:  You probably need to adjust C:\logs\processor.ps1 to a valid path on your computer.

Guy Recommends:  A Free Trial of the Network Performance Monitor (NPM)Review of Orion NPM v10

SolarWinds' Network Performance Monitor will help you discover what's happening on your network.  This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.

What I like best is the way NPM suggests solutions to network problems.  Its also has the ability to monitor the health of individual VMware virtual machines.  If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.

Download a free trial of Solarwinds' Network Performance Monitor

Example 3: Get-Counter Process

Preliminary Research: Let us get a list of process properties or paths, incidentally, you check the available counters in Task Manager.

# PowerShell Get-Counter Process
(Get-Counter -ListSet Process).paths

Actual Experiment to monitor Process Virtual Bytes.

Clear-Host
$Proc = Get-counter "\Process(*)\Virtual Bytes"
$Proc.CounterSamples | Format-Table InstanceName, CookedValue -auto

Note: While this is a real example, it's meant to give you a template which you can alter to suit your project, for example, you not only change 'Virtual Bytes' for 'Working Set', but you could choose a completely different counter, for example 'Memory' or 'Processor'.  To see what I mean go back to -ListSet in Example 1.

Example 4: WMI Alternative to Get-Counter

This example maybe a step too far, or it may just alert you do a parallel technique, where you employ WmiObject instead of Get-Counter.

This, and similar scripts, will only return data if you are logged on as an administrator.

# PowerShell Performance and WMI
$Disk = Get-WmiObject -class Win32_PerfRawData_PerfDisk_LogicalDisk
$Disk | Get-Member

Note 4a:  The above little script reveals over 50 disk properties.  The main features of these counters are Read or Write, Average or Percentage.

SolarWinds Firewall Browser Solarwinds Free Firewall Browser

Here is an utility where you can review firewall settings such as access control lists (ACL), or troubleshoot problems with network address translation (NAT).

Other reasons to download this SolarWinds Firewall Browser include managing requests to change your firewall settings, testing firewall rules before you go live, and querying settings with the browser's powerful search options.

Guy recommends that you download a copy of the SolarWinds free Firewall Browser.

Research Similar PowerShell Counter Cmdlets

# PowerShell Counter Cmdlet Research
Clear-Host
Get-Command -Noun Counter

The above script reveals the sister commands Import-Counter and Export-Counter. While it's moderately easy to see what these cmdlets do, I have never seen anyone use them in real-life. 

Summary of PowerShell Get-Counter Cmdlet

To be frank, as someone who is a minor expert in both PowerShell and performance monitoring I would encourage to seek other methods of achieving your goals before turning to Get-Counter.

If you like this page then please share it with your friends

 


See More Windows PowerShell Examples of Real-life Tasks

PowerShell Tutorials  • PowerShell Examples  • IpConfig  • Get-Counter  • PowerShell NetSh

Monitor Performance - PowerShell  • PowerShell temp   • PowerShell Delete Temporary files

PowerShell WOL (Wake-on-Lan)  • Services   • Change Computer Description Registry

Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.

Download my ebook:Getting Started with PowerShell
Getting Started with PowerShell - only $9.25

You get 36 topics organized into these 3 sections:
   1) Getting Started
   2) Real-life tasks
   3) Examples of Syntax.

In addition to the ebook, you get a PDF version of this  Introduction to PowerShell ebook  It runs to 120 pages of A4.

 *


Custom Search

Site Home

Guy Recommends: WMI Monitor for PowershellSolarwinds WMI Monitor

Windows Management Instrumentation (WMI) is most useful for PowerShell scripting.

SolarWinds have produced this Free WMI Monitor to take the guess work out of which WMI counters to use for applications like Microsoft Active Directory, SQL or Exchange Server.

Download your free copy of WMI Monitor

Author: Guy Thomas Copyright © 1999-2013 Computer Performance LTD All rights reserved.

Please report a broken link, or an error to: