Enable Windows feature from PowerShell

Enable Windows feature from PowerShell


With PowerShell, Windows finally get to be a bit funier, allowing you to do a lot of things, and automate a lot of them without having to click around the interface. Here is how to enable Windows features in the terminal without saving a considerable number of clicks and especially having the chance to put it all in an easily executable script on another machine.
This can prove very useful in the mass server deployment or in configuring machines.

To start enter the Import-Module ServerManager Cmdlet, if you have an error it means that the necessary components are not installed, you can get a package at the following address to fix this : https://www.microsoft.com/en-us/download/details.aspx?id=7887. Depending on your distribution it is possible that your system may not be compatible, there is an fix to compensate for that is described at the end of the article.

After installation performed retype Import-Module ServerManager and start working with the provided tools. If you encounter the problem again, restart PowerShell and if that does not suffice restart your machine. First you can list active features by using Get-WindowsFeature. You will find in this list the items available for your distribution, their “human friendly” names, their status (installed or not) and their code name, it’s the name you’ll use to enable or disable a component.

When you have selected the list of features you want to install on your computer, launch the Add-WindowsFeature with setting up the list of features:

Add-WindowsFeature -Name Net-HTTP-Activation,Web-Common-Http,Web-ASP-Net

You can also add the -IncludeAllSubFeature setting to enable the lower elements in the tree to be also installed.

And so it is with the Remove-WindowsFeature for the reverse operation.

I would make a point later on automated configuration of an IIS server with the creation of websites, application pool and creating applications inside the site.

For those who do not have the chance to have “recent” servers or distributions, here the parade.

pkgmgr.exe /ui:Net-HTTP-Activation;Web-Common-Http;Web-ASP-Net

Here it is necessary to select all the necessary features.