Install Windows Server Roles with Desired State Configuration (DSC)

In this blog post, I will show you how to use Desired State Configuration (DSC) to install Windows Server roles on multiple machines or a single server including localhost

More Articles In This Series

Configure Desired State Configuration (DSC) Push Settings

About DSC

DSC is a configuration manager that helps us manage our servers and at the same time keep them compliance with tools, roles and features.

At the core, DSC is using PowerShell and WinRM to manage Windows machines as you will see shortly.

Environment

In this demo, I will deploy the configuration to a machine called server01 to install the Group Policy Management console (GPMC).

You can also test this code on your local machine by changing the node name to localhost.

If you would like to apply the configuration to multiple machines use the following format node “server1”, “server2”

Code

Configuration GPMC {
Import-DscResource -ModuleName PsDesiredStateConfiguration
 
  Node "server01" {      
     WindowsFeature gpmc {
        Ensure = "present"
        Name = "GPMC"
   
 
} 
}
}
 
GPMC

In the following code, I will install the GPMC console on a server called server01.

Go ahead and save the file as a PowerShell script (PS1).

In the screenshot below you can see the code.

Compile Configuration

Before deploying the DSC configuration, we need to compile (dot sourcing) it using the . .nameofscript.ps1 and as shown below.

. .\install.ps1

After compiling the code, DSC will create a folder called GPMC and a .mof file that contain the configuration.

Deploy

It is time to deploy the code, and I will do it using the start-sdcconfiguration command with the path to the folder above.

Start-DscConfiguration -path C:\dsc\GPMC -Wait -Verbose -Force

Test and check

To test if the configuration and deployment were successful, I can type the command below.

Test-dscconfiguration

As you can see below, GPMC has appeared on my server.

Processing…
Success! You're on the list.

Posted

in

by