Manage Windows Features with PowerShell: Add Feature or Role

In part one of this two-part series, I showed you how to configure and manage Windows features using Windows PowerShell and the ServerManager module. Naturally, the next step is to add a feature or role. We’ll pick up where the last article left off in a remote PowerShell session.

To get back up to speed, I want to identify File-Service sub features that are not installed.

I’m betting you can figure out the name of the cmdlet to add a Windows feature.

Using –Whatif is a smart idea here as I can see that some additional features will also be installed. When I’m ready, I can re-run this command without –Whatif.

In this particular case, no reboot was required. If it had been, I could reboot the server whenever I wanted with Restart-Computer, or wait until the next scheduled maintenance window. If you know in advance that installing a feature or role will require a reboot and you don’t mind rebooting immediately, use the –Restart parameter. If no reboot is required, then the parameter should be ignored.

Some features or roles include a number of sub-roles, as we’ve seen. You can either install a group of roles or you might decide to install a feature or role with all of its subroles.

I don’t need this feature but I wanted to show you how the parameters work. If you attempt to install a group of features that happen to have other requirements, you will be prompted to install them as well. In an automated solution, you will want to identify these situations ahead of time and install all the necessary features at once or in the right order.

The last management task is removing a feature. On my server, someone has mistakenly installed Telnet tools.

I want to delete them. The Remove-WindowsFeature cmdlet doesn’t support wildcards so I would have to type the names out, separated by commas. I’d rather have PowerShell do the work.

When I run the command without –Whatif, the features will be removed. There are any number of ways you might leverage this type of pipelined expression to remove non-standard features or to insure servers meet your build standards. And to repeat, we did all of this without any scripting. All we did was run some commands from a PowerShell prompt.

If you are interested in learning about other ways to manage your servers with Windows PowerShell, I hope you’ll take a look at my video training course, Windows Server 2008 PowerShell Training.

Related Topics:

  • PowerShell

    Don't have a login but want to join the conversation? Sign up for a Petri Account