How to Enumerate all WMI Classes
Jomo Fisher—Quick sample today. I’m mainly posting this because it took me a while to figure it out and I hope it might save someone some time. This is the F# code you would useto enumerate all WMI classes on your system and show the properties of each. of each.
Code Snippet
- // WalkWmiTypes.fsx
- // Enumerate all WMI types on the local machine and show their property names and types.
- #r "System.Management"
- open System.Management
- let scope = ManagementScope("\\\\localhost\\root\\cimv2")
- let path = ManagementPath("")
- let mclass = new ManagementClass(scope, path, ObjectGetOptions())
- let options = EnumerationOptions()
- options.EnumerateDeep <- true
- for obj in mclass.GetSubclasses(options) do
- printfn "%s" (obj.ToString().Split(':').[1])
- for prop in obj.Properties do
- printfn " %s:%A" prop.Name prop.Type
This is pure .NET, so it should be easily translatable to C# and VB. Let me know if you run into problems with that. The result looks like:
Output
- Msft_WmiProvider_DeleteClassAsyncEvent_Post
- ClassName:String
- Flags:UInt32
- HostingGroup:String
- HostingSpecification:UInt32
- Locale:String
- Namespace:String
- ObjectParameter:Object
- provider:String
- ResultCode:UInt32
- SECURITY_DESCRIPTOR:UInt8
- StringParameter:String
- TIME_CREATED:UInt64
- TransactionIdentifer:String
- User:String
This posting is provided "AS IS" with no warranties, and confers no rights.