18

I'm trying to move the verification & creation of my performance counter groups, and the counters themselves, out of my web service and into a powershell script that's run during deployment.

Can this be done? Or am I stuck using a simple app to build the groups & counters?

Thanks much :)

2
  • I'd also love to know if there is a way to update the counters from a powershell script or command line? Commented Oct 8, 2010 at 9:23
  • How do we use PowerShell to create a permanent counter for Average64, those requiring AverageBase? Commented Nov 20, 2017 at 20:51

1 Answer 1

15

Figured this out a while ago, but never posted.
Here's my solution:

//save out the type name for sanity's sake
$ccdTypeName = 'System.Diagnostics.CounterCreationData'
$CounterCollection = New-Object System.Diagnostics.CounterCreationDataCollection

//create as many counters as we'd like, and add them to the collection. here's just one:
$CounterCollection.Add( (New-Object $ccdTypeName "Counter Name", "Counter Description", NumberOfItems32) )

//create the category with the counter collection
[System.Diagnostics.PerformanceCounterCategory]::Create($perfCounterCategoryName, $perfCounterVersion, [Diagnostics.PerformanceCounterCategoryType]::SingleInstance, $CounterCollection); 
Sign up to request clarification or add additional context in comments.

2 Comments

Nice example of how to in detail on TechNet as of 2014. blogs.technet.com/b/omx/archive/2014/04/23/…
Note from the blogs.technet.com post, "The instances will go away when PowerShell exits. These instances are only available while your script is running." If you convert either this SO answer to C# or the blog's code to C#, they are permanent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.