Using Powershell to install roles


So, you’ve got your server 2k8 R2 installed as a base installation and you want to install a few roles onto it. You can use powershell to do this.

I know your asking “why when I can go through a few menus and its done”, humour me and it may save you some time.

To work with roles and powershell you will need to open powershell (duh). Before you can actually start tapping out the commands for installing services you will need to enable the modules within powershell.

So to begin with you will need to type:

import-module Servermanager

After you have completed that you can then type:


Which will output a rather verbose list of roles and features that can be installed onto a server 2008 R2 box (already installed roles will be documented with an [X]). For a more sensible list that you can reference I would use the command:

Get-Windowsfeature > c:features.txt

Which would write the contents of the output into the features file on the C drive which I find easier to work with.

now the important bit installing features with powershell. You can install roles and features listed in the output given in the above command by typing add-windowsfeature “Name” where the “Name” you should replace it with the Name (note not Display Name) of the feature you wish to install.

You can test the predicted result of an installation of a role or feature by using the -whatif command for example add-Windowsfeature “Name” -whatif would run a simulated installation and produce a hopefully positive outcome, Its also quite handy for finding out if the server will need a reboot for the role so you can find out beforehand what you need to schedule in.

Now all this is fairly academic until you maybe starting thinking about multiple servers what if you were in a large organisation or just somewhere that bought a few servers, clicking through menus X amount of times suddenly seems a bit of a drag. So what you have got above is the ability to script role and feature installs in your servers. So for instance if you wrote the below in a txt file and called it something.ps1 then you could push it out to the brand new servers and have the roles auto install for you.

import-module Servermanager
Add-Windowsfeature “Name”


You could also add -restart after the role to restart the computer if it needs to after the role has installed.

You could save yourself a good bit of time when you have set this up correctly. Because its powershell you will have to allow powershell scripts to run which you can do by typing “set-executionpolicy unrestricted” which of course I would recommend you change back after the scripts you want to run have completed.

With a combination of scripts and your favourite distribution method you could shorten the time it takes to install the roles quite considerably thus giving you more time for Angry Birds which of course is always appreciated!

Leave a Reply