IIS App Pool to the “Performance Monitor Users”

Sitecore Error

I am familiar with this error from working with Sitecore.

[Error] Cannot load Counter Name data because an invalid index '' was read from the registry.

However, you may encounter this error when running your own applications and experiencing difficulties accessing the performance counters in Windows.


This code adds the IIS App Pool to the “Performance Monitor Users” group.

# 2023-11-01
# Add IIS to performance monitor users

$groupName = "Performance Monitor Users"

# Get the "Performance Monitor Users" group
$group = [ADSI]"WinNT://$Env:ComputerName/$groupName,group"

# Get a list of IIS application pools
$appPools = Get-IISAppPool | Where-Object { $_.Name -notlike "*.NET*" }

foreach ($appPool in $appPools) {
    $ntAccount = New-Object System.Security.Principal.NTAccount("IIS APPPOOL\" + $appPool.Name)
    $strSID = $ntAccount.Translate([System.Security.Principal.SecurityIdentifier])
    $user = [ADSI]"WinNT://$strSID"
    Write-Host "Added $($appPool.Name) to $groupName"

Please note that this code assumes you are using PowerShell and have the appropriate permissions to execute it.