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.
- // 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(‘:’).)
- 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:
This posting is provided “AS IS” with no warranties, and confers no rights.