Share via


PowerShell DSC modifying MOF File manually

Question

During PowerShell session UNIX admin asked this "Can I write MOF file myself rather than using PowerShell?"

Answer

In PowerShell 5.0 we do have Class - So MOF is not really necessary for DSC. However to answer the question. Yes it's possible, provided you know how to do that. Oops! I was not aware that he is from UNIX back ground. Questioner blasted in his demo

Demo

MOF File I have will set BITS to Running state and Start up type as Automatic.

Code

/*
@TargetNode='DSC'
@GeneratedBy=ChenV
@GenerationDate=12/22/2014 11:25:00
@GenerationHost=DSC
*/

instance of MSFT_ServiceResource as $MSFT_ServiceResource1ref
{
ResourceID = "[Service]SetBITS";
 State = "Running";
 SourceInfo = "::5::9::Service";
 Name = "BITS";
 StartupType = "Automatic";
 ModuleName = "PSDesiredStateConfiguration";
 ModuleVersion = "1.0";

 ConfigurationName = "SetBITS";

};
instance of OMI_ConfigurationDocument
{
 Version="2.0.0";
 MinimumCompatibleVersion = "1.0.0";
 CompatibleVersionAdditionalProperties= {"Omi_BaseResource:ConfigurationName"};
 Author="ChenV";
 GenerationDate="12/22/2014 11:25:00";
 GenerationHost="DSC";
 Name="SetBITS";
};

Modifying the Code

/*
@TargetNode='DSC'
@GeneratedBy=ChenV
@GenerationDate=12/22/2014 11:25:00
@GenerationHost=DSC
*/

instance of MSFT_ServiceResource as $MSFT_ServiceResource1ref
{
ResourceID = "[Service]SetBITS";
 State = "Stopped";
 SourceInfo = "::5::9::Service";
 Name = "BITS";
 StartupType = "Manual";
 ModuleName = "PSDesiredStateConfiguration";
 ModuleVersion = "1.0";

 ConfigurationName = "SetBITS";

};
instance of OMI_ConfigurationDocument
{
 Version="2.0.0";
 MinimumCompatibleVersion = "1.0.0";
 CompatibleVersionAdditionalProperties= {"Omi_BaseResource:ConfigurationName"};
 Author="ChenV";
 GenerationDate="12/22/2014 11:25:00";
 GenerationHost="DSC";
 Name="SetBITS";
};

Note: State = "Running"; Changed to State = "Stopped";
Execute the below code to see the configuration change.

Start-DscConfiguration -Path C:\SetBITS -Wait -Verbose -Force