Cleaning up CCS perf counter entries

Just a quick note. When you uninstall CCP V1, the performance counter categories "Compute Cluster" and "Compute Nodes" aren't removed. (This is a bug which will be resolved in V2.) This means that if for some reason these entries get corrupted, they can be hard to clean up. I encountered this because of an unrelated bug where the performance counter names for the Japanese CCP were localized.

Corrupt entries can cause errors like:

C:\>cluscfg view
Counter 'Total number of jobs' does not exist in the specified Category.

Another symptom is a dialog when trying to submit a job from the job scheduler that says: "Total processor number is zero. Cannot submit job."

In any case, the following PowerShell script can be used to clean up these entries after uninstalling the CCP. (Don't run it while the CCP is still installed! In V1, you can technically stop the Microsoft Compute Cluster Scheduler Service, run this script and then restart the service and it will re-populate the counters, but if you have corruption and don't know how it get there, it might be best to just re-install the CCP.)

$objperfcats = [System.Diagnostics.PerformanceCounterCategory]
$objperfcats::GetCategories() | where-object {$_.CategoryName -eq "Compute Cluster"
-or $_.CategoryName -eq "Compute Nodes" } | foreach { $objperfcats::Delete($_.CategoryName) }