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
- Deploying the MOF into server which can happen in two ways
- Execution Phase
- In this MOF file will be executed by Local Configuration Manager.
- Authoring Phase:
Push based Model

Pull Based Model

Hello-World Configuration
- Create a PS1 file with the Sample DSC Configuration as shown below

- Now, Generate MOF file by executing the powershell file

- 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

- Powershell works very well in a domain controller. So the lab setup would be as shown below

- Next Steps:
- Configuration Data
- Configuration
- DSC Resources & Modules
- Powershell DSC to install web servers
