On systems where I've implemented minimally privileged domain service accounts for SQL Server services I've run into a problem accessing perf counter data using the System.Diagnostics.PerformanceCounter object. If I run perfmon the counters all return valid results, and I get proper values from the OS counters (Pct Processor Used, Available Memory, etc.) through the PerformanceCounter object, but the SQL Server counters all return zero.
The service accounts are part of an AD group, and I've added that group to both the Performance Log Users and Performance Monitor Users groups in the local machine.
Any idea why this is happening? I've got scripts that have worked everywhere else, but this one client, and I'm not sure where to look to find it. (I've refreshed the counters – they work in perfmon.)
I think you might get a better response from something like StackOverflow.com – only because this isn't PowerShell per se; you're dealing with the .NET Framework classes and it's more likely someone over there has done so.
I unfortunately don't know enough about how SQL works with those counters, although have you tried accessing them via WMI instead? I'm just wondering if that'd be any different. The fact that they work in PerfMon is vexing.
Vexing is a good way to put it, Don. If I run PowerShell as Administrator, the counters return valid values as well, but my login is part of the local Admin group and returns 0, unless I run PowerShell as Administrator. I just don't know what security settings it requires to get valid values.