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.

Notes:

  • 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
{
Node "WIN-K8EBFDLD1KU"
{
#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

Webserver

Next start the DSC configuration:

Start-DscConfiguration -Path Webserver -Wait -Verbose

Next view the DSC configuration:

Get-DscConfiguration

To check Is the DSC operation completed successfully use:

Get-DscConfigurationStatus


Posted

in

by

Comments

One response to “Use PowerShell DSC To Install And Remove Server Roles”

  1. […] page was successful in installing IIS, but it doesn’t create a configuration file. This ntweekly page DOES provide configuration script, and this blog page helps to clearly explain the syntax of a […]