Install IIS (or any role and feature) on Windows Server 2012 with Powershell

In Windows Server 2012 -just like in the previous version – you can add IIS through the Add roles and features wizard. The GUI navigates you all the steps necessary for the installation and offers you the option to install any additional role service considering dependencies.

Add roles and features wizard
Add roles and features wizard

Meet the commandlets

Sometimes you may want to automate this with Powershell locally, or remotely for multiple machines. DISM module offers the same commandlets as available in Windows 8 but in the server edition using ServerManager module you may want to use the following commands:

  • Get-WindowsFeature: lists available roles, role services and features
  • Install-WindowsFeature: installs roles role services and features
  • Uninstall-WindowsFeature: uninstalls roles, role services or features

The names and functionality are very straightforward.

If you want to read about Get-WindowsOptionalFeature, Enable-WindowsOptionalFeature, Disable-WindowsOptionalFeature of the DISM module in Windows 8, please read this post: Install IIS on Windows 8 with Powershell

Commands to manage roles and features in Server 2012
Commands to manage roles and features in Server 2012

List roles, role services and features

To list installed and available roles, role services and features on the localhost, simply type Get-WindowsFeature without any parameter. This command gives you a neat table with the name, display name and install state, all properties you might need in a basic scenario.

Example of Get-WindowsFeature
Example of Get-WindowsFeature

To gather more information about all or any individual role or role service, use wildcards with the name parameter of the commandlets and dump all properties in a list view:

Get-WindowsFeature -Name web-server | Format-List -Property *

With this you can see the type (role, role service, feature), dependencies and parent-child relationships of any item.

Windows feature with all properties
Windows feature with all properties

It is important to mention that this command works on VHD files – just use the –vhd parameter with a path -, can connect to a remote computer with the -computername parameter, and you can submit additional credentials using –Credential.

Install roles

In a basic way you can use the Install-WindowsFeature command and submit the name of a role, role service or feature. For example to install IIS with the default configuration use this:

Install-WindowsFeature -Name Web-Server

Installing IIS
Installing IIS

Because we are working on a server product the commandlets only tells you at the end of the installation in a message that restart is needed. In case you want to restart automatically when the installation finished, specify the -Restart switch.

Please note, that you cannot use wildcards in the names of features, instead use Get-WindowsFeature, and pipe the result to the install commandlet.

This command also works on VHD files and remote machines, just specify them using -vhd, or -ComputerName parameters respectively.

After the installation is finished you might want to launch a management tool – or use powershell 🙂 – to configure the server role. But by default this install commandlet does not include management tools!

IIS is installed but without management tools
IIS is installed but without management tools

To avoid this situation you have to add the -IncludeManagementTools switch in your commands.

To remedy the current situation with the installed web server role without management tools use Install-WindowsFeature again.

Install-WindowsFeature -Name Web-Mgmt-Tools

This gives you the well known IIS manager among the Admin Tools.

IIS Manager in Administrative Tools
IIS Manager in Administrative Tools

To further fine tune your server first retrieve the feature name with the get command, then install it using the install command.

Finally if you want to get rid of any role or feature use the Uninstall-WindowsFeature command.

Advertisements

1 thought on “Install IIS (or any role and feature) on Windows Server 2012 with Powershell”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s