Automate IIS Setup and Features with Powershell

about 2 minutes to read

Recent versions of Windows and Windows Server let you install additional features through PowerShell. The IIS Web Server is not installed by default, but you can automate the process by using a Powershell script to install it.

Web Connection ships with a PowerShell script file Install-IIS_Features.ps1 which contains the commands to install IIS with the recommended features needed to run IIS for Web Connection.

Running Install-IIS-Features.ps1

The script is simply a bunch of Enable-WindowsOptionalFeature commands strung together to install the relevant IIS features.

To do this:

  • Open a PowerShell Command Prompt as Administrator
  • cd
  • Run: Install-IIS-Features.ps1

The commands will execute one after the other.

Script Content

For completeness sake here's the content of this file:

powershell
# This script installs IIS and the features required to # run Web Connection. # # * 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 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 NetFx4Extended-ASPNET45 Enable-WindowsOptionalFeature -Online -FeatureName IIS-NetFxExtensibility45 Enable-WindowsOptionalFeature -Online -FeatureName IIS-HealthAndDiagnostics Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpLogging Enable-WindowsOptionalFeature -Online -FeatureName IIS-LoggingLibraries 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-WebServerManagementTools Enable-WindowsOptionalFeature -Online -FeatureName IIS-IIS6ManagementCompatibility 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

There are a few other optional components and setting that I recommend you also install/configure:

powershell
# The following optional components require # Chocolatey OR Web Platform Installer to install # Install UrlRewrite Module for Extensionless Urls (optional) ### & "C:\Program Files\Microsoft\Web Platform Installer\WebpiCmd-x64.exe" /install /Products:UrlRewrite2 /AcceptEULA /SuppressPostFinish # choco install urlrewrite -y # Install WebDeploy for Deploying to IIS (optional) ### & "C:\Program Files\Microsoft\Web Platform Installer\WebpiCmd-x64.exe" /install /Products:WDeployNoSMO /AcceptEULA /SuppressPostFinish # choco install webdeploy -y # Disable Loopback Check on a Windows Server (or Enterprise Win 10) # Gets around no local Logins on Windows Server # New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name "DisableLoopbackCheck" -Value "1" -PropertyType dword # To list all Windows Features: dism /online /Get-Features # Get-WindowsOptionalFeature -Online # LIST All IIS FEATURES: # Get-WindowsOptionalFeature -Online | where FeatureName -like 'IIS-*'

Chocolatey

I highly recommend that you install the Chocolatey Package Manager for new server or any new machine installs in general, to automate the installation of the most common components and some common configuration operations. Chocolatey lets you do unattended installs of most Tools and Components and servers with a single command that can be automated.

For example here's my server installation script:

powershell
# Run from ADMIN POWERSHELL PROMPT # Install Chocolatey #Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) choco install disableuac # Apps choco install vscode -y choco install GoogleChrome -y choco install filezilla -y choco install 7zip -y choco install git -y choco install tortoisegit -y choco install xplorer2 -y choco install procexp -y choco install westwindwebsurge -y choco install MarkdownMonster -y choco install deletefiles -y choco install filezilla.server -y choco install sql-server-express -y choco install sql-server-management-studio -y choco install robo3t -y

© West Wind Technologies, 1996-2024 • Updated: 05/22/20
Comment or report problem with topic