Fix “106” Performance Counter events on Exchange servers
You might have seen lots of errors in the Application log of your Exchange 2013 server from source MSExchange Common and event id 106.
Performance counter updating error. Counter name is PowerShell Average Response Time, category name is MSExchangeRemotePowershell. Optional code: 2. Exception: The exception thrown is : System.InvalidOperationException: The requested Performance Counter is not a custom counter, it has to be initialized as ReadOnly.
The issue is caused by an error in the Exchange setup process where a performance counter definition is tried to read from the wrong location.
The good news is that we can fix this very easy. Copy the following script to a text file and save with the .ps1 extension.
Add-PsSnapin Microsoft.Exchange.Management.PowerShell.Setup
$files = Get-ChildItem “c:\Program Files\Microsoft\Exchange Server\V15\setup\perf\*.xml”
Write-Host “Registering the perfmon counters”
Write-Host
$count = 0;
foreach ($i in $files)
{
$count++
$f = $i.directory, “\”, $i.name -join “”
Write-Host $count $f -BackgroundColor red
New-PerfCounters -DefinitionFileName $f
}
Run the script from an Exchange management shell.
If you run into issues you can manually retry the process for that specific performance counter definition. For instance, to retry the failed counter definition from the screenshot above you can retry the action:
Add-PsSnapin Microsoft.Exchange.Management.PowerShell.Setup
New-PerfCounters -DefinitionFileName “C:\Program Files\Microsoft\Exchange Server\V15\setup\perf\WorkerTaskFrameworkPerfCounters.xml”
Interesting detail is that Microsoft apparently wrote a KB article about this issue back in 2013 which I failed to pick up. I modified the script to work on servers with Exchange installed in a non-default path. If you prefer to use the original one, don’t forget to change the path manually.