Duplicate Windows Servers: install Roles and Features with PowerShell

RSAT Tools were usually considered the best friend of a Windows system administrator, offering access to servers directly from any workstation. SCCM for endpoint and server management on medium/large organisations is maybe even more!
In my humble opinion Powershell should be considered or should become the best friend of every Windows System Administrator.

When workloads increase or for testing purpose is a very common request to provision a server with the same specs of an existing one,  a freshly installed clone. For instance, can we collect information in a similar manner by just using a scripting language without using other tools? In this article we will see how.

Without getting too much into detail the first step is to spin up a VM with the same OS and resources. There are a lot of ways of creating golden images or generalise an image with sysprep.

Installing roles and features are usually performed remotely most of the time without the need of connecting via RDP.  Indeed, comparing Roles and Features installed can be performed remotely :

Once connected is required to import  ServerManager Powershell module:

To obtain a list of the installed roles and feature on the remote server:

Important Note: Get-WindowsFeature can be run remotely with -computername in order to get all features installed on the target machine.

If we are want to install to the new server all the roles and feature installed on the old one we can

If we want to export it and save it  (even on a shared folder):

To install from xml :

Some features require restart use -restart option or just add a Restart-Computer at the end of the script.

If you want to repeat this process or do it in a more DevOps way, the best way with PowerShell is to have a look at DSC (Desired State Configuration).

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.