Here's an oldie but goodie, that keeps coming up for me rather frequently. I've been working with IIS on Windows for a loooong time and I have a number of products that go way back that run on IIS. As a result I deal with a lot of support issues around IIS and people who install IIS run an application for years, have their servers eventually break down and then have to reinstall years after their last install. And a lot of times the people who set up the system are long gone.

The chief complaints I hear frequently is that it's a pain to get IIS to install initially with all the right components. I tend to agree - especially on Server versions installing IIS through the insanely user hostile Server Manager interface is a pain.

But there's an easier, quicker and repeatable way if you're willing to dive into the command line or create and run a small Powershell script.

Enter Enable-WindowsOptionalFeature

Apparently many people are unaware that in recent versions of Windows - using Powershell - you can automate the IIS Features installation using a few simple Powershell Commandlet calls. It's as easy as creating a small PowerShell script file and letting her rip.

You can use the Enable-WindowsOptionalFeature command to install IIS Features as well as any other Windows Features. This command works both on desktop and server versions (server versions also have Enable-WindowsFeature which has the same effect) and makes it pretty easy to automate an IIS install by whittling away a few commands in a POSH script file.

You can tweak and fiddle with the features you actually need for IIS, but the above is pretty standard for my base installs.

Put the above into a POSH script file (SetupIIS.ps1) and then:

Open a PowerShell command prompt using Run as Administrator

Run the script

Additional IIS Features

Two more features that I typically use on IIS and aren't directly includable features are WebDeploy and UrlRewrite. You can install those from the Web Platform installer, or - which is easier in my case - from Chocolatey:

choco install webdeploy /y
choco install urlrewrite /y

What Windows Optional Features are Available?

Enable-WindowsOptionalFeature is great, as long as you know what's available. Luckily it's easy to figure out what's available and what's installed and what's not.

Discover Features with PowerShell ISE

There are obviously a lot more options you can set on these components, but it's easy to find out about those. I also recommend that while you're discovering features, use the PowerShell ISE shell (run from the Start menu using Run as Administrator) to discover what's available:

Figure 1 - Powershell ISE lets you get Intellisense on commands and live object instances

The Intellisense in the editor and the command window gives you live property values on commands and even live objects as shown in the Figure 1 which makes it relatively easy to figure out settings. For the rest the various cmd-lets and admin objects are well documented and searchable.

Summary

None of this is new of course, but it's always good to be reminded that you can automate installation and configuration of IIS relatively easily. This is especially true since I just this week I heard from several people how much of a pain IIS can be to install and get up and running. It doesn't have to be this way... the tools are there.

The Voices of Reason

Very useful Rick! For some reason IIS does not come as standard with the very useful feature to import an application as a ZIP file and Microsoft make it super hard to find the link to download that add-on. It forces you to first install the "Web Platform Platform Installer Platform" or something, and then find an obscure link. I'm guessing that can't be done from PowerShell, but it sure would be useful.

This looks good, Rick. I ended up doing something similar with Desired State Configuration (DSC) to configure IIS the way that I wanted. https://msdn.microsoft.com/en-us/powershell/dsc/windowsfeatureresource This simplifies the re-running of my configuration script, but doesn't always provide the level of granularity that I need. I combined it with non-DSC PowerShell that manually checks to see if things are already configured, and now have a re-runnable script that I can run on my "pet" servers. Maybe this will become less important once I start treating my servers more like cattle, and stand up new ones every deployment.

Nice! -- I noticed a couple of these error out because a parent feature is not installed; it looks like if you add the "-All" switch to end of each of the "Enable-WindowsOptionalFeature" commands, then you will not encounter this issue (also, some of the commands are listed more than once, I'm guessing that was to combat this issue, but with -All, it's not necessary anymore).

Also, I prepended my script with this (to make sure it only ran if IIS was missing):

you have to put the Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASPNET45 as the last line of the script: instead you'll get a registry error (which probably is the "One or several parent features are disabled so current feature can not be enabled." on Winsrv 2016 )
Thanks!