24/7/365 Support

Access Windows Performance Counters

Problem

You want to access system performance counter information from PowerShell.

Solution

To retrieve information about a specific performance counter, use the System. Diagnostics.PerformanceCounter class from the .NET Framework, as shown in Example 156.

Example 156. Accessing performance counter data through the System.Diagnostics. PeformanceCounter class

PS >$arguments = "System","System Up Time" PS >$counter = NewObject System.Diagnostics.PerformanceCounter $arguments PS > PS >[void] $counter.NextValue() PS >NewObject TimeSpan 0,0,0,$counter.NextValue()

Days
: 0

Hours
: 18

Minutes
: 51

Seconds
: 17

Milliseconds
: 0

Ticks
: 678770000000

TotalDays
: 0.785613425925926

TotalHours
: 18.8547222222222

TotalMinutes
: 1131.28333333333

TotalSeconds
: 67877

TotalMilliseconds : 67877000

Alternatively, WMI’s Win32_Perf* set of classes support many of the most common performance counters:

GetWmiObject Win32_PerfFormattedData_Tcpip_NetworkInterface

Discussion

The System.Diagnostics.PerformanceCounter class from the .NET Framework provides access to the different performance counters you might want to access on a Windows system. Example 156 illustrates working with a performance counter from a specific category. In addition, the constructor for the PerformanceCounter class also lets you specify instance names, and even a machine name for the performance counter you want to retrieve.

The first time you access a performance counter, the NextValue() method returns 0. At that point, the system begins to sample the performance information and returns a current value the next time you call the NextValue() method.

Help Category:

Get Windows Dedicated Server

Only reading will not help you, you have to practice it! So get it now.

Processor RAM Storage Server Detail
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 1 TB (HDD SATA) Configure Server
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 128 GB (SSD SATA) Configure Server
Intel Atom C2750 2.4 GHz 8c/8t 8 GB DDR3 1× 1 TB (HDD SATA) Configure Server
Intel Xeon E3-1230 v2 3.3 GHz 4c/8t 16 GB DDR3 1× 256 GB (SSD SATA) Configure Server
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 250 GB (SSD SATA) Configure Server

What Our Clients Say