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

  1. // WalkWmiTypes.fsx
  2. // Enumerate all WMI types on the local machine and show their property names and types.
  3. #r "System.Management"
  4. open System.Management
  6. let scope = ManagementScope("\\\\localhost\\root\\cimv2")
  7. let path = ManagementPath("")
  8. let mclass = new ManagementClass(scope, path, ObjectGetOptions())
  9. let options = EnumerationOptions()
  10. options.EnumerateDeep <- true
  12. for obj in mclass.GetSubclasses(options) do
  13.     printfn "%s" (obj.ToString().Split(':').[1])
  14.     for prop in obj.Properties do
  15.         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:


  1. Msft_WmiProvider_DeleteClassAsyncEvent_Post
  2.     ClassName:String
  3.     Flags:UInt32
  4.     HostingGroup:String
  5.     HostingSpecification:UInt32
  6.     Locale:String
  7.     Namespace:String
  8.     ObjectParameter:Object
  9.     provider:String
  10.     ResultCode:UInt32
  12.     StringParameter:String
  13.     TIME_CREATED:UInt64
  14.     TransactionIdentifer:String
  15.     User:String

This posting is provided "AS IS" with no warranties, and confers no rights.