Use PowerShell DSC To Install And Remove Server Roles

In this article I’ll show you how I use PowerShell Desired State Configuration (DSC) to make sure a server has all the required roles and features necessary for deployment.

DSC had been released with Windows Server 2012 R2 and also comes with Server 2016 RTM which was released two weeks ago.

Using DSC you could:

  • Install \ Remove server roles and features
  • Manage registry settings
  • Manage files and folders
  • Stop \ start processes
  • Manage local users and groups
  • Run PowerShell scripts
  • Align “drifted” servers from the DSC comfig

In my example I’ll use DSC to install and make sure IIS Server Role In Installed.


  • The script can be extended to be used for Installing multiple roles
  • To get the list of roles and feature use get-windowsfeature and use the name property
  • To remove a role using DSC you need to set the Ensure value to Absent

Below you will see the code for one server role Install:

Configuration webserver
#Install the IIS Role
WindowsFeature IIS
Ensure = "Present"
Name = "Web-Server"

Save to script and run using . .\ to register webserver variable:

. .\WebDSC.ps1

Next, type the webserver variable


Next start the DSC configuration:

Start-DscConfiguration -Path Webserver -Wait -Verbose

Next view the DSC configuration:


To check Is the DSC operation completed successfully use:


1 thought on “Use PowerShell DSC To Install And Remove Server Roles”

Comments are closed.