Forum Discussion
Fantastic - Thanks!
I got this working this morning. One key for anyone else who wants to use this: I had to run it signed in as Administrator rather than my normal ID with Admin rights. The script ran, but I got all zeros for values when I was not running as administrator.
Also, I used your script to create two more so that I could write these out to a csv file for graphing and analysis. It was a very simple matter, but I'm sharing them to save someone time if they are new to this or haven't scripted in a while, as I haven't.
One script writes the Counter Names (prop.Name) to the header row of a .csv file. I execute it before entering my Data-Driven or For Loop. The other one writes out the Counter Values (prop.Value) to the .csv file within the loop.
First
Create csv File and Headers:
Sub Write_CLRCountersToHeader
' My process name
myProcess = "_Global_" ' You can specify your executable's name here, e.g. Orders
computerName = "." ' You can specify your computer name here
' Connect to WMI via COM
Set objWMIService = GetObject("winmgmts:\\" & computerName & "\root\cimv2")
Set PerfProcess = objWMIService.Get( _
"Win32_PerfFormattedData_NETFramework_NETCLRMemory.Name='" & myProcess & "'")
'Creates a new file.
Call aqfile.Create("FilePath\CLRCounters.csv") 'Change FilePath to the path to the directory where you want to put the file'
' Writes each property name to the CSV Header Line .
s = ""
For Each prop In PerfProcess.Properties_
s = s & prop.Name & ","
Next
Call aqFile.WriteToTextFile("FilePath\CLRCounters.csv", s & vbCrLf, 20) 'Must be same path and filename as above
End Sub
Second Script
Write CLR Counter Values to csv Within a Loop:
Sub Write_CLRCounterValuesToCSV
' My process name
myProcess = "_Global_ " ' You can specify your executable's name here, e.g. Orders
computerName = "." ' You can specify your computer name here
' Connect to WMI via COM
Set objWMIService = GetObject("winmgmts:\\" & computerName & "\root\cimv2")
Set PerfProcess = objWMIService.Get( _
"Win32_PerfFormattedData_NETFramework_NETCLRMemory.Name='" & myProcess & "'")
' Writes each property to the CSV Header Line .
s = ""
For Each prop In PerfProcess.Properties_
s = s & aqConvert.VarToStr(prop.Value) & ","
Next
Call aqFile.WriteToTextFile("FilePath\CLRCounters.csv",s & vbCrLf, 20)
End Sub
Related Content
- 11 months agosal21
- 9 months agoEgg
- 11 years agomurugans1011
Recent Discussions
- 7 hours agoSubhraDas
- 21 hours agoJacobjacob44