15 October 2012

Read performance counters from powershell

in good old command prompt typeperf can be used but from what i manged to test is not working ok on windows 2003 (it is not returning process description; it return just counters event if i use some letters and * wildchar and should return more than one process);

use typeperf /? or technet (http://technet.microsoft.com/en-us/library/bb490960.aspx) for usage information;

with powershell we have Get-Counter cmdlet but the use of * wildchar and letters at the same time is not supported on windows 2003 and XP;

best sollution i found was to use WMI from powershell:


Get-WmiObject win32_PerfFormattedData_PerfProc_Process -Filter "Name like 'powersh%'" | Select-Object Name, PercentProcessorTime


Name                      PercentProcessorTime
----                            --------------------
powershell               98
powershell#1           0


14 October 2012

Performance counter with PID information

In order to retreive a process PID from performance counters you need to create the nex registry key which will add the process PID to the process name:

Location: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\PerfProc\Performance
Type: DWORD
Name: ProcessNameFormat
Value: 2

After the new key is added the performance counter process name will look like this:

InstanceName
-----------------
svchost_1144
spoolsv_1032
frameworkservice_1360


Source: http://support.microsoft.com/kb/281884

12 October 2012

Generate CPU load

a neat trick to generate cpu load:

$result = 1; foreach ($number in 1..2147483647) {$result = $result * $number};

can be extend to:

foreach ($loopnumber in 1..2147483647) {$result=1;foreach ($number in 1..2147483647) {$result = $result * $number};$result}

source: http://waynes-world-it.blogspot.ro/2009/05/generating-100-cpu-with-calc-or.html