-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-LocalPerfCounterName.ps1
35 lines (28 loc) · 1.25 KB
/
Get-LocalPerfCounterName.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# source: https://www.msxfaq.de/code/powershell/psperfcounter.htm
# https://www.ip-insider.de/leistungs-monitoring-mit-dem-windows-admin-center-a-921043/
# https://www.channelpartner.de/a/know-how-windows-performance-counter,633709
function Get-LocalPerfCounterName {
param (
[Parameter(Mandatory=$true)]
$Name
)
$key009 = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009'
$counters009 = (Get-ItemProperty -Path $key009 -Name Counter).Counter.tolower()
$Index = $counters009.IndexOf($name.tolower())
if ($index -eq -1) {
$null # not found
}
else {
$keylocal = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\CurrentLanguage'
$counterslocal = (Get-ItemProperty -Path $keylocal -Name Counter).Counter
$counterslocal[$index]
}
}
# Get CPU Load with local Perfmon names
# Normal localized Version
#(get-counter "\prozessor(_total)\prozessorzeit (%)").countersamples.cookedValue
# Get CPU Load using english names as source
$counter="Processor"
$Subcounter = "% Processor Time"
$instance = "_Total"
(get-counter "\$(get-LocalPerfCounterName $counter)($($instance))\$(get-LocalPerfCounterName $subcounter)").countersamples.cookedValue