DSC Example

I create dsc1.ps1 on my domain controller, dc-1.

Configuration DscConfiguration
{
    param
    (
        [string[]]$ComputerName='localhost'
    )

    Import-DscResource -ModuleName PsDesiredStateConfiguration

    Node $ComputerName
    {
        WindowsFeature MyFeatureInstance
        {
            Ensure = 'Present'
            Name = 'RSAT'
        }

        WindowsFeature My2ndFeatureInstance
        {
            Ensure = 'Present'
            Name = 'DNS'
        }
        File HelloWorld {
            SourcePath = "C:\Users\Administrator\Documents\jor.txt"
            DestinationPath = "C:\Temp\HelloWorld.txt"
            Ensure = "Present"
            Contents   = "Hello World from DSC!"
        }
    }
}
DscConfiguration

Anatomy

The outer block is the configuration block, with the name DscConfiguration. We could add the node to run this against using

Node @('localhost', 'server-1')

In my script, I added a parameter so that the computers this will act against can be entered at the command line. Below I just use the ComputerName parameter “localhost”.

Last updated