This document provides an overview of Desired State Configuration (DSC) in PowerShell 4.0. DSC is a new management platform for managing configuration data which helps prevent configuration drift and supports DevOps practices. It provides language extensions and cmdlets to manage configuration using built-in and custom resources. Custom resources can be created by defining a MOF file and PowerShell module with functions for getting, setting, and testing the resource state. DSC configurations specify the desired state and are compiled into MOF files. The local configuration manager on each machine with PowerShell 4.0 is responsible for executing resources to ensure the system is in the desired state. Configurations can be delivered using a push or pull model.
2. About Me
• Work at Dell Inc.
• Windows PowerShell MVP since 2010
• Founder and Editor of PowerShell
Magazine
• Twitter: @Ravikanth
• Facebook: /Ravikanthc
• http://www.powershellmagazine.com
• http://www.ravichaganti.com/blog
3. Desired State Configuration
• A new management platform for
management of configuration data
– Helps prevent configuration drift
– Helps DevOps!
• Provides
– Language Extensions
– Cmdlets to manage configuration
– Built-in resources
4. DSC Basics …
Configuration ArchiveDemo {
Node SRV3-WS2012R2 {
Archive ArchiveDemo {
Path = "10.10.10.101BackupScripts.zip"
DestinationPath = "C:Scripts"
Ensure="Present"
}
}
}
ArchiveDemo
Declarative Syntax
.PS1
• Can take
parameters like a
function
• Uses PowerShell
Remoting
• Each Configuration
document gets
converted to a
MOF
5. DSC Resources
Archive Environment File Group
Log Package Process Registry
Role Script Service User
… Of course, You can build your own resources
7. Custom DSC Resources
• Create a MOF file describing the resource
• Create a PowerShell Module (PSM1 & PSD1)
– Set-TargetResource
– Test-TargetResource
– Get-TargetResource
– Must be idempotent
• Copy all files to
C:Windowssystem32WindowsPowerShellv1.0Mo
dulesPSDesiredStateConfigurationPSProviders
8. Custom Resource - MOF
[version("1.0.0"), FriendlyName("HostsFile")]
class HostsFile : MSFT_BaseResourceConfiguration
{
[Key] string hostName;
[Key] string ipAddress;
[write,ValueMap{"Present", "Absent"},Values{"Present",
"Absent"}] string Ensure;
};
• [Key] for unique
attributes; become
mandatory
• [Write] for
attributes for which
a value can be
specified
• [Read] for readonly
attributes
• ValueMap defines
the possible values
• Naming:
classname.schema.
mofHostsFile.Schema.Mof
9. Custom Resource – Module
• Same parameters on
– Get-TargetResource
• Must return hashtable of the configuration
– Set-TargetResource
– Test-TargetResource
• Must return true or false
• Module Manifest is required
– Use New-ModuleManifest
12. DSC Configuration Data
• Separate business logic from configuration
data
• Makes configuration logic more re-usable
$AllNodes = @(
@{ NodeName = "*"; RecurseValue = $true },
@{ NodeName = “SRV2"; HostName = "Web01";
IPAddress = “10.10.10.101"; },
@{ NodeName = “SRV3"; HostName =
"Web02"; IPAddress = “10.10.10.102"; },
);
13. DSC – Local Configuration Manager
• Each computer with PS 4.0 runs a DSC
Engine (as SYSTEM)
• Responsible for calling the DSC resources
• LCM properties can be updated to use pull
model; of course, using DSC
15. Configuration Delivery
• Push
– Default delivery mechanism
– Start-DSCConfiguration
• Pull
– DSC Service
– IIS Endpoint
– Requires
• Windows Server 2102 or
• Windows Server 2012 R2
16. Summary
• Understanding DSC and implementing custom
resources can change the way configuration
management is done
• Endless opportunities for System
administrators and DevOps engineers