Chris Hall bio photo

Chris Hall

Principal Technical Consultant

PolarCloudsUK Chris LinkedIn Github
Chris Hall Nutanix Certified Master - Multicloud Infrastructure 6 Chris Hall VMware vExpert 2024 Chris Hall VMware vExpert NSX 2023 Chris Hall Nutanix Certified Professional - Multicloud Infrastructure 6 Chris Hall Nutanix Certified Professional - Unified Storage 6 Chris Hall VMware vExpert 2023 Chris Hall VMware vExpert 2022
Mmmm a Roll with a Ham Feature...

Quite often I'm asked to build servers that need to have identical configurations in terms of the Windows roles and features installed.


Firstly, What are server roles, role services, and features?  Have a look at this article to understand roles and features and the difference between a Windows role and a Windows feature.


Export and Import of Windows Roles and Features

OK, so I've manually installed a selection of required roles and features on the first of my servers and that server is working perfectly.  How can I export a list of roles and features installed on the working server so that I can build the second server?

Powershell to the rescue!
This is where the powershell Server Manager Module comes into it's own.  It has three handy cmdlets, they are:
  • Add-WindowsFeature
  • Get-WindowsFeature
  • Remove-WindowsFeature
 Lets look at the Server Manager Module in action:

PS> Import-Module Servermanager
PS> Get-Command -Module Servermanager


So if we list all installable modules:

PS> Get-WindowsFeature


Lots and lots!  OK lets pair this down and see if we can list only those roles and feature installed.  We use this command:
PS> Get-WindowsFeature | ? { $_.Installed }


Nice.  Now we know which roles and features are installed. Handy for documentation or comparison.

HOW TO: Export Installed Roles and Features to File

Firstly you need to export that nice list obtained above into something structured that can be used by the other server to install the required roles and features.  For this we use the Export-Clixml cmdlet.  This will allow us to export the list of installed roles and features into an xml file. Here is the command with the xml creation:

PS> Get-WindowsFeature | ? { $_.Installed -AND $_.SubFeatures.Count -eq 0 } | Export-Clixml .\RnF.xml

The resulting xml file looks like this:


OK, lets copy this xml file over to our target server ready for the import.

 HOW TO: Install Roles and Features from File

Dead simple, using the Import-Clixml cmdlet:
 
PS> Import-Module Servermanager
PS> Import-Clixml .\RnF.xml | Add-WindowsFeature


Quick check in Server Manager GUI:


Looks Good. Job done!


So there you have it then. Two commands, one piece of xml, two servers running the exact same set of roles and features.

- Chris