Windows Server 2016 – Installing the Web Server role with PowerShell

How to Create a web API with ASP.NET Core 3.1

If you haven’t started using PowerShell to accomplish some of your regular Windows Server tasks, do it now! PowerShell can be used in Windows Server 2016 to accomplish any task or configuration inside the operating system. I am a huge fan of using the keyboard instead of the mouse in any circumstance, and saving scripts that can be used over and over to save time in the future.

In this recipe, we are going to explore the Install-WindowsFeature cmdlet, which can be used to add a role or roles to your Server 2016. Since we are discussing IIS in this chapter, let’s take our newly created web server and use PowerShell to place the Web Server (IIS) role onto it.

Getting ready

There is a new Windows Server 2016 web server in our environment called WEB2. Let’s use PowerShell on this machine in order to install the IIS role.

How to do it…

To add the Web Server (IIS) role to WEB2 via PowerShell, follow these steps:

  1. Log in to WEB2 and open a PowerShell prompt; make sure to run it as administrator.
  1. All we have to do is run the proper cmdlet specifying the role name, but the specific name of our role evades me. Well, not really, but I thought this would be a good opportunity to explore another command that will help us see a list of the available roles to be installed. Type the following command to see the list of roles:
      Get-WindowsFeature
  1. Whoa! There’s a big list of all the roles and features that can be installed on this server. Scrolling up, I can see Web Server (IIS) in the list, and it looks like the role name is Web-Server. I am going to keep that name in mind, and since we have the ability to install multiple items at the same time, I am also going to note Web-Common-Http in order to install the common HTTP features when I install the role:
  2. Now we need to build out the PowerShell command to install these two items:
          Install-WindowsFeature Web-Server,Web-Common-Http,Web-Mgmt-
            Console -Restart
  1. Installation succeeded! Just to double-check it for the sake of our recipe, if we navigate through the GUI to see the installed roles and features, we can see that the items we configured via PowerShell are fully installed:

How it works…

We can use the Install-WindowsFeature cmdlet in PowerShell to easily add roles and features to our servers. This one can save a lot of time compared to running through these options in the graphical wizards. For example, if you had a group of new servers that all needed to accomplish the same task, and therefore needed the same set of roles installed, you could build out one single command to install those roles and run it on each server. No need to launch Server Manager at all.

See also

Here are some links to additional TechNet documentation on adding roles to servers, and specifically for the Install-WindowsFeature cmdlet. Make sure to familiarize yourself with all of the available options. Once you start using this command, I doubt you will go back to Server Manager!

  • http://technet.microsoft.com/en-us/library/cc732263.aspx#BKMK_powershell
  • http://technet.microsoft.com/en-us/library/jj205467.aspx

Comments are closed.