DSC - jasper-zanjani/Windows-Server GitHub Wiki

IaaS management of servers is possible with Desired State Configuration (DSC), a feature of Windows PowerShell where script files stored on a central server can apply specific a specific configuration to nodes. These scripts are idempotent, meaning that they can be applied repeatedly without generating errors.

The DSC model is composed of phases

  1. Authoring Phase, where MOF definitions are created
  2. Staging Phase, where declarative MOFs are staged and a Configuration calculated per node
  3. "Make It So" Phase, where declarative Configurations are implemented through imperative providers

Components of DSC scripts include:

  • Local Configuration Manager: engine running on the client system that received configurations from the DSC server and applies them to the target.
  • Node block specifies the names of target computers.
  • Resource block specifies settings or components and the values that the configuration script should assign to them.

DSC configurations can be deployed in two different refresh modes

Pull architecture: target LCM periodically retrieves configuration from a Pull Server, which consolidates MOF files. Push architecture: configuration is sent to target in response to explicit invocation of Start-DSCConfiguration on the server.

LCM has to be configured to accept Configurations of either refresh mode.

PowerShell

PowerShell cmdlets for DSC are implemented in the psdesiredstateconfiguration module. Only a very few DSC cmdlets remain supported in PowerShell 7: these are marked below.

Cmdlet Description
New-DscCheckSum Creates checksum files for DSC documents and DSC resources.
Get-DscConfiguration Gets the current configuration of the nodes.
Publish-DscConfiguration Publishes a DSC configuration to a set of computers.
Restore-DscConfiguration Reapplies the previous configuration for the node.
Start-DscConfiguration Apply configuration to nodes
Stop-DscConfiguration Stops a running configuration.
Test-DscConfiguration Tests whether the actual configuration on the nodes matches the desired configuration.
Update-DscConfiguration Checks the pull server for an updated configuration and applies it.
Remove-DscConfigurationDocument 7 Removes a configuration document from the DSC configuration store.
Get-DscConfigurationStatus Retrieves data about completed configuration runs.
Disable-DscDebug Stops debugging of DSC resources.
Enable-DscDebug Starts debugging of all DSC resources.
Get-DscLocalConfigurationManager 7 Gets LCM settings and states for the node.
Set-DscLocalConfigurationManager 7 Applies LCM settings to nodes.
Get-DscResource Gets the DSC resources present on the computer.
Invoke-DscResource Runs a method of a specified DSC resource.

Tasks

Set LCM to push mode

[DSCLocalConfigurationManager()]
Configuration LCMConfig {
  Node localhost {
    Settings {
      RefreshMode = 'Push'
}}}

Install Telnet client

Configuration InstallTelnetLocal { 
  Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
  Node localhost {
    WindowsOptionalFeature InstallTelnet {
      Name = "Telnet-Client"
      Ensure = "Present"
}}}

Install WSL

Configuration InstallWSLLocal { 
  Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
  Node localhost   {
    WindowsOptionalFeature InstallWSL     {
      Name = "Microsoft-Windows-Subsystem-Linux"
      Ensure = "Present" 
}}}
⚠️ **GitHub.com Fallback** ⚠️