Windows Classroom Series – 28/Oct/2020

Powershell DSC (Desired State Configuration)

  • Powershell DSC helps ensuring resources are correctly configured. Powershell DSC is a declarative way of configuring resources.
  • Powershell DSC is released as a feature of Powershell.
  • Powershell DSC as a set of Powershell Language Extensions
  • A Sample DSC would look like
configuration TemporaryConfiguration 
{
   File TempFile 
   {
         Ensure = 'Present'
         Type = 'File'
         DestinationPath = 'C:\temp.txt'
         Contents = 'This is sample DSC Configuration'
   }
}
  • In the above case we are expressing the desired state rather than writing how to create a file.

High level Overview

  • DSC has several steps that can be grouped into three phases
    • Authoring Phase:
      • We begin with writing DSC Configuration script in Powershell.
      • Generate a MOF (Managed Object Format) for the configuration
    • Staging Phase
      • Deploying the MOF into server which can happen in two ways
        • PUSH
        • PULL
    • Execution Phase
      • In this MOF file will be executed by Local Configuration Manager.

Push based Model

Preview

Pull Based Model

Preview

Hello-World Configuration

  • Create a PS1 file with the Sample DSC Configuration as shown below Preview
  • Now, Generate MOF file by executing the powershell file Preview Preview Preview
  • Lets look into contents of mof
/*
@TargetNode='localhost'
@GeneratedBy=qtkha
@GenerationDate=10/28/2020 17:55:51
@GenerationHost=DESKTOP-45IKD7M
*/

instance of MSFT_LogResource as $MSFT_LogResource1ref
{
SourceInfo = "D:\\khajaclassroom\\windows\\powershell\\dsc\\hello-dsc\\hellodsc.ps1::8::5::Log";
 ModuleName = "PsDesiredStateConfiguration";
 ResourceID = "[Log]MyMessage";
 Message = "Hello, Welcome to the World of DSC";

ModuleVersion = "1.0";

 ConfigurationName = "HelloDsc";

};
instance of OMI_ConfigurationDocument


                    {
 Version="2.0.0";
 

                        MinimumCompatibleVersion = "1.0.0";
 

                        CompatibleVersionAdditionalProperties= {"Omi_BaseResource:ConfigurationName"};
 

                        Author="qtkha";
 

                        GenerationDate="10/28/2020 17:55:51";
 

                        GenerationHost="DESKTOP-45IKD7M";
 

                        Name="HelloDsc";


                    };

  • Now lets execute the MOF file by using the cmd-let Start-DSCConfiguration
Start-DscConfiguration -Path .\HelloDSC -Wait -Verbose

Preview

  • Powershell works very well in a domain controller. So the lab setup would be as shown below Preview Preview
  • Next Steps:
    • Configuration Data
    • Configuration
    • DSC Resources & Modules
    • Powershell DSC to install web servers

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube