You are on page 1of 10

Automating IIS Feature Installation with Powershell - Rick Strahl's Web Log Page 1 of 10

Contact   •   Articles  
○ ○
Ad-free experience sponsored by:
ASPOSE - the market leader of .NET and Java APIs for file formats – natively work with DOCX, XLSX,
PPT, PDF, images and more 

Automating IIS Feature Installation with Powershell

 May 25, 2017 • from Hood River, OR   •    9 comments Share on:



○ ○
 ○


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

https://weblog.west-wind.com/posts/2017/May/25/Automating-IIS-Feature-Installatio... 10/10/2018
Automating IIS Feature Installation with Powershell - Rick Strahl's Web Log Page 2 of 10

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.

Here's what I typically use to configure my base version of IIS:


# * Make sure you run this script from a Powershel Admin Prompt!
# * Make sure Powershell Execution Policy is bypassed to run these scripts:
# * YOU MAY HAVE TO RUN THIS COMMAND PRIOR TO RUNNING THIS SCRIPT!
Set-ExecutionPolicy Bypass -Scope Process

# To list all Windows Features: dism /online /Get-Features


# Get-WindowsOptionalFeature -Online
# LIST All IIS FEATURES:
# Get-WindowsOptionalFeature -Online | where FeatureName -like 'IIS-*'

Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole


Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServer
Enable-WindowsOptionalFeature -Online -FeatureName IIS-CommonHttpFeatures
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpErrors
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpRedirect
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ApplicationDevelopment
Enable-WindowsOptionalFeature -Online -FeatureName IIS-NetFxExtensibility45
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HealthAndDiagnostics
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpLogging

Enable-WindowsOptionalFeature -Online -FeatureName IIS-LoggingLibraries
 

https://weblog.west-wind.com/posts/2017/May/25/Automating-IIS-Feature-Installatio... 10/10/2018
Automating IIS Feature Installation with Powershell - Rick Strahl's Web Log Page 3 of 10

Enable-WindowsOptionalFeature -Online -FeatureName IIS-RequestMonitor


Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpTracing
Enable-WindowsOptionalFeature -Online -FeatureName IIS-Security
Enable-WindowsOptionalFeature -Online -FeatureName IIS-RequestFiltering
Enable-WindowsOptionalFeature -Online -FeatureName IIS-Performance
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerManagementToo
Enable-WindowsOptionalFeature -Online -FeatureName IIS-IIS6ManagementCompatib
Enable-WindowsOptionalFeature -Online -FeatureName IIS-Metabase
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ManagementConsole
Enable-WindowsOptionalFeature -Online -FeatureName IIS-BasicAuthentication
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WindowsAuthentication
Enable-WindowsOptionalFeature -Online -FeatureName IIS-StaticContent
Enable-WindowsOptionalFeature -Online -FeatureName IIS-DefaultDocument
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebSockets
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ApplicationInit
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ISAPIExtensions
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ISAPIFilter
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpCompressionStatic
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASPNET45

# If you need classic ASP (not recommended)


#Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASP

#REM The following optional components require


#REM Chocolatey OR Web Platform Installer to install

#REM Install UrlRewrite Module for Extensionless Urls (optional)


#REM & "C:\Program Files\Microsoft\Web Platform Installer\WebpiCmd-x64.exe" /
choco install urlrewrite -y

#REM Install WebDeploy for Deploying to IIS (optional)


#REM & "C:\Program Files\Microsoft\Web Platform Installer\WebpiCmd-x64.exe" /
choco install webdeploy -y
 
Put the above into a POSH script file ( SetupIIS.ps1 ) and then:

• Open a PowerShell command prompt using Run as


Administrator

• Run the script

https://weblog.west-wind.com/posts/2017/May/25/Automating-IIS-Feature-Installatio... 10/10/2018
Automating IIS Feature Installation with Powershell - Rick Strahl's Web Log Page 4 of 10

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

To see all the features available related to IIS you can use:

Get-WindowsOptionalFeature -Online | where FeatureName -like 'IIS-*'

 

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.

Check for Installed Features:

Get-WindowsOptionalFeature -Online | where {$_.state -eq "Enabled"

 

Check for Features available but Not Installed

Get-WindowsOptionalFeature -Online | where {$_.state -eq "Disabled"

 

Disable a Windows Feature

Disable-WindowsOptionalFeature -Online -FeatureName IIS-DirectoryBrowsing

 

https://weblog.west-wind.com/posts/2017/May/25/Automating-IIS-Feature-Installatio... 10/10/2018
Automating IIS Feature Installation with Powershell - Rick Strahl's Web Log Page 5 of 10

Create an IIS Application Pool and Web Site


For bonus points, lets also create an Application Pools and attach a Web
site/Virtual to it. You can configure IIS via more powershell helpers by using the
WebAdministration powershell module (most like already installed):

Import-Module WebAdministration

Once installed it's easy to create a new WebSite and Application Pool.

To create an Application Pool:

New-WebAppPool -name "NewWebSiteAppPool" -force

$appPool = Get-Item -name "NewWebSiteAppPool"


$appPool.processModel.identityType = "NetworkService"
$appPool.enable32BitAppOnWin64 = 1
$appPool | Set-Item

Then to create a Web Site:

md "c:\Web Sites\NewWebSite"

# All on one line


$site = $site = new-WebSite -name "NewWebSite"
-PhysicalPath "c:\Web Sites\NewWebSite"
-HostHeader "home2.west-wind.com"
-ApplicationPool "NewWebSiteAppPool"
-force

 

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:

https://weblog.west-wind.com/posts/2017/May/25/Automating-IIS-Feature-Installatio... 10/10/2018
Automating IIS Feature Installation with Powershell - Rick Strahl's Web Log Page 6 of 10

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.

this post created and published with Markdown Monster

Other Posts you might also like

• Using Let's Encrypt with IIS on Windows

• Web Browser Control & Specifying the IE Version

https://weblog.west-wind.com/posts/2017/May/25/Automating-IIS-Feature-Installatio... 10/10/2018
Automating IIS Feature Installation with Powershell - Rick Strahl's Web Log Page 7 of 10

• Use IIS Application Initialization for keeping ASP.NET Apps alive

• Capturing Performance Counter Data for a Process by Process Id

  
 
Is this content useful to you?
Share on:  Consider making a small
donation to show your support.

Posted in IIS Windows

The Voices of Reason

# re: Automating IIS Feature Installation with


Powershell

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
Rich
and Microsoft make it super hard to find the link to download that
May 26, 2017
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.

# re: Automating IIS Feature Installation with


Powershell

Rich,
SomeUser
Web Deploy can be downloaded without WebPI
May 27, 2017
(https://www.iis.net/downloads/microsoft/category/deploy-and-
migrate). While it is possible to use PowerShell (or any other
scripting toy, or msiexec) to get the bits installed, the installer's user
interface is the only documented way to fully customize the setup.

https://weblog.west-wind.com/posts/2017/May/25/Automating-IIS-Feature-Installatio... 10/10/2018
Automating IIS Feature Installation with Powershell - Rick Strahl's Web Log Page 8 of 10

# re: Automating IIS Feature Installation with


Powershell

This looks good, Rick. I ended up doing something similar with


Desired State Configuration (DSC) to configure IIS the way that I
Jon
wanted. https://msdn.microsoft.com/en-
May 30, 2017
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.

# re: Automating IIS Feature Installation with


Powershell

Does anyone know, how to enable (IIS 6 Management Console, IIS


6 Scripting Tools, IIS 6 WMI Compatibility) using command line?
Jan
This is for Windows 7 Enterprise 64 bit
August 20, 2017

# re: Automating IIS Feature Installation with


Powershell

I second the need for a powershell script for IIS 6. I'm currently
writing an automated installation for BizTalk 2016 and part of the
Chad
prerequisites are:
October 18, 2017

For Windows 10 In Web Management Tools: also check: IIS 6


Management Compatbility IIS 6 Management Console IIS 6
Scripting Tools IIS Metabase and IIS confirguration compatibility IIS
Management Console

In Wold Wide Web Services, expand Security and also check: Basic
Authentication Windows Authentication

https://weblog.west-wind.com/posts/2017/May/25/Automating-IIS-Feature-Installatio... 10/10/2018
Automating IIS Feature Installation with Powershell - Rick Strahl's Web Log Page 9 of 10

# re: Automating IIS Feature Installation with


Powershell

@Jan - use Get-WindowsOptionalFeature and look through the


Rick Strahl
list - it's in there. See how I query for features not installed int the
October 18, 2017
post.

# re: Automating IIS Feature Installation with


Powershell

Thanks for posting Rick, very useful.


John
I got an error on Windows 2016 (1607):- IIS-NetFxExtensibility, IIS-
March 18, 2018
NetFxExtensibility45, IIS-ASPNET45 all errored with:

Enable-WindowsOptionalFeature : One or several parent features are

 
I enabled the following feature and then the above worked:
NetFx4Extended-ASPNET45

Enable-WindowsOptionalFeature -Online -FeatureName NetFx4Extended-A

 

# re: Automating IIS Feature Installation with


Powershell

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
Mikey
end of each of the "Enable-WindowsOptionalFeature" commands,
June 07, 2018
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):

$installed = (Get-WindowsOptionalFeature -Online | `


where { $_.state -eq "Enabled" -and $_.FeatureName -eq

 

https://weblog.west-wind.com/posts/2017/May/25/Automating-IIS-Feature-Installatio... 10/10/2018
Automating IIS Feature Installation with Powershell - Rick Strahl's Web Log Page 10 of 10

if ($installed -gt 0) { return; }

# re: Automating IIS Feature Installation with


Powershell

Great article! I've found two small problems on Windows 10 1709:


Alberto
• add Enable-WindowsOptionalFeature -Online
June 14, 2018
-FeatureName NetFx4Extended-ASPNET45 instead of
Enable-WindowsOptionalFeature -Online
-FeatureName IIS-NetFxExtensibility45 (which
probably is a typing mistake)

• 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!

Add a Comment

© Rick Strahl, West Wind Technologies, 2005 - 2018

https://weblog.west-wind.com/posts/2017/May/25/Automating-IIS-Feature-Installatio... 10/10/2018

You might also like