Question

I'm looking for a way to programatically change features ("Programs and Features" -> "Turn Windows Features on or off") in Windows Vista (and newer Redmond OS, e.g. Server 2008).

Ideal solution would be in the form of a Powershell script (Get-Features, Set-Features), however any pointers to MSDN/other documentation would be very welcome! (my initial quick Google/StackOverflow search came up empty).

Having an automatic way to turn features on or off would allow me to automate computer setup for different scenarios. For example, to develop ASP.NET applications using IIS a bunch of IIS features need to be installed that are not installed by default. My current process of "make sure at least the features shown in this screenshot are checked" leaves a lot to be desired.

Was it helpful?

Solution

I just found an extension that works for Windows 7. "PowerShell module to Add/Remove Windows 7 features" - https://psclientmanager.codeplex.com/

OTHER TIPS

in windows server 2008, there is the ServerManagerCmd command. This can install IIS with or without the subfeatures you want. You can also install/uninstall most of the major Windows features.

  1. You can setup your server the way you want then run ServerManagerCmd -query template.xml. This exports the configuration to an Xml file.
  2. You need to transform the file to prepare it for use on other servers
  3. Copy the transformed file to the server you want to configure and run ServerManagerCmd -inputPath transformTemplate.xml

The way to do this in Vista and Windows 2008 is with the PKGMGR command line tool. Search MSDN for this tool to find a list of features/packages.

It looks live Powershell V2 on Server 2008 R2 (Beta) has a module that does exactly this. Let's hope Windows 7 will have this functionality as well...

For more details, see Managing Server Features with PowerShell Cmdlets on Windows 2008 Server R2 Beta

There's unfortunately not a set of cmdlets, yet, nor is there anything in WMI or any other easily-accessible area. Interestingly, Server Core's script-based role management features will only work on Server Core :). Windows 7 may bring some relief in this regard - but it also might not. In the meantime, you're pretty much left with the native Win32 APIs mentioned in the other answer.

As an aside, I should point out that MS deliberately doesn't want applications installing major OS features due to the security considerations. Adding IIS isn't something done lightly, and it brings with it security considerations and responsibilities. Witness MS' own application setups, which check for pre-reqs like that, but do not offer to install them for you. While I understand wanting to make your app setup as painless as possible, there's also damage to be done in putting major functionality into the OS under someone's nose :). I personally would prefer that apps err on the side of caution, tell me what they need, and let me make the decisions about how and what to install things - especially major functionality that will open ports and be able to execute arbitrary code, like IIS.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top