Skip navigation

Control Windows Features with PowerShell Cmdlets

PowerShell brings a little something extra to the process

Windows Server 2008 changes the whole process of server configuration, thanks to a big GUI shift—for example, you don't use Control Panel to add or remove a server feature anymore; you use the new Server Manager snap-in—and to the addition of two new command-line tools (OCSetup and Servermanagercmd) that let you add or remove features. In last month's column ("Control Windows Features with DISM," InstantDoc ID 103118), I noted with some surprise that with the advent of Server 2008's replacement, Server 2008 R2, Microsoft shook things up even further by deprecating Servermanagercmd and Oclist, replacing them with two even newer commands: Deployment Image Servicing and Management (DISM) and three new PowerShell cmdlets. Last month's column covered DISM, so now let's look at the PowerShell offerings.

Server 2008 R2 ships with a PowerShell 2.0–compatibile module called ServerManager that—when imported—adds three PowerShell cmdlets: add-windowsfeature, get-windowsfeature, and remove-windowsfeature. Their function closely approximates what the dism /online /enable-feature, dism /online /get-features, and dism /online /disable-feature commands do, but they add some of that characteristic extra functionality that we've come to expect from PowerShell cmdlets.

Before running the cmdlets, you'll need to start up an elevated PowerShell prompt (right-click the blue PowerShell icon, choose Run as Administrator, and confirm the User Account Control—UAC—prompt) and type

import-module servermanager

Then, you can get started with the Server Manager cmdlets by typing


which produces a list of roles, role services, and features, all under the label features. (Like DISM, PowerShell thankfully doesn't perpetuate the silly division of "stuff the server can do" into roles versus features.) Each list entry contains the special name that you need to use if you want to enable or disable that feature. For example, here are a few lines of its output:

 \\[ \\] DHCP Server 	DHCP 
\\[X\\] DNS Server DNS \\[ \\] Fax Server Fax
\\[ \\] File Services File-Services
\\[ \\] File Server FS-FileServer

The single X next to DNS Server specifies that I have the DNS Server role installed on the system and that I don't have the DHCP Server, Fax Server, File Services, and File Server role services installed. (A role service is, in Server 2008 R2 parlance, "just a part of a role.") The names on the right—DHCP, DNS, Fax, File-Services, and FS-FileServer—are the exact names that you'd feed into the next Server Manager cmdlet, add-windowsfeature.

To add the File Server role service to this server, I'd type

add-windowsfeature fs-fileserver

That syntax probably doesn't surprise you—so far, it's similar to last month's DISM example, and it's pretty intuitive.

But you will be pleasantly surprised about a few other aspects this command. First, notice that the get-windowsfeature command reported that the role service's name is FS-FileServer, not fs-fileserver, as I typed. Remember that annoying insistence on particular uppercase and lowercase in DISM's "magic names" for roles and features? PowerShell doesn't impose that irritation.

Second, you can install more than one feature by merely separating them with commas, as in

add-windowsfeature dhcp, fax, file-services

Compare that simple list-formatted syntax to DISM's irritating need to prefix every feature with /featurename, and you'll start liking the Server Manager cmdlets. Notice also that you can separate the items in an add-windowsfeature list either with commas or with commas and spaces, as I've done. In my opinion, the comma/space separator makes for more readable commands. (It's a shame that you don't get the Server Manager cmdlets after installing the Remote Server Administration Tools (RSAT)—and a bit puzzling, because RSAT provides the 70-odd Active Directory (AD)-related cmdlets to Windows 7 users. Why not the mere three in the Server Manager group?)

To remove a feature from a server, just use the remove-windowsfeature cmdlet, using the same options as add-windowsfeature. For example,

remove-windowsfeature dhcp, fax

The remove-windowsfeature and add-windowsfeature cmdlets include two more useful options: -restart and -whatif. Regular PowerShell users will know that -whatif appears on just about any PowerShell cmdlet that might undesirably modify your system. This option causes the PowerShell cmdlet to make no actual changes but instead to report what it will do if you leave -whatif off. It ranks as one of my favorite PowerShell features: Nerf bumpers for administrators!

Finally, when added to add-windowsfeature or remove-windowsfeature, the -restart option authorizes PowerShell to reboot if necessary to complete your addition or removal.

If you haven't yet given PowerShell a try, the Server Manager cmdlets are a gentle introduction to a helpful set of command-line tools. Next month, I'll take them further, revealing more of the cmdlets' power.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.