Playing with MOF and WMI

Started by spl, Today at 07:15:27 AM

Previous topic - Next topic

spl

While .mof files are generally used for DSC configurations of servers or local machines, they supposedly work well with WMI. I am a dummy when it comes to DSC but have posted WQL scripts over the years.

The code below is an example of creating/removing a WMI Namespace called Winbatch. Of course the .mof files could be created manually in Notepad and later compiled with mofcomp.exe. Be fun to go further
  • Create Class or Classes for Winbatch Namespace
  • Create Properties for Classes
  • Create Instance for Properties


but so far have been unable to find a good reference, i.e. what are all the pragmas, syntax for defining properties, instances.
;NOTE: Using ## to avoid invalid char error
mof = $"##pragma namespace("\\\\.\\Root")

instance of __Namespace
{
    Name = "WinBatch";
};
$"

mofile = "C:\temp\CreateWB.mof"
If Fileexist(mofile) Then Filedelete(mofile)
FilePut(mofile,mof)
If FileExist(mofile) Then Message("MOF File Created",mofile)
Exit

;you can run "mofcomp.exe c:\temp\CreateWB.mof" as mofcomp should be installed in \systen32
;after you confirm the Namespace was created use this

mofile = "C:\temp\CreateWB.mof"
If Fileexist(mofile)
   delmofile = "C:\temp\RemoveWB.mof"
   mof=$"##pragma namespace("\\\\.\\Root")

   ##pragma deleteinstance
       ("__Namespace.Name='WinBatch'", FAIL)
   $"
   FilePut(delmofile,mof)
Endif
Exit
;and run  "mofcomp.exe C:\temp\RemoveWB.mof"
;and include error-handler to catch errors for the FAIL option
Stan - formerly stanl [ex-Pundit]

JTaylor

Very Interesting.

Just to make sure I understand...you can populate the DSC this way and then use WMI to pull the info like you can do for things like the system hardware configuration?

Jim


JTaylor

A further question, what advantage would you gain doing something like this over using the registry?  Would be this more broadly accessible?

Jim