views:

452

answers:

5

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.

A: 

Hi

You should be able to use the SystemParametersInfo API from user32 which has been available since Windows2000. This is a native Win32 API but you should be able to wrap the calls in a managed assembly using P/Invoke and use this from powershell (I'm no powershell expert).

Look at these for more info:

Good luck!

Edit: Hmm, I just realized that this was not at all an answer to your question, I'm really sorry (I think I read it too fast). What is good manners here, should I delete my question?

Carl Serrander
Yeah, if it isn't relevant I would say that it should be deleted.
Ian Robinson
Please delete your answer so that it's not confusing others investigating this issue. Thanks, Milan.
Milan Gardian
A: 

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.

Don Jones
Well I would like to be able to setup my machines in a repeatable manner. I want all my dev machines to have some specific features installed. Are you saying it's BETTER to manually select all the features for EVERY machine based on screenshots/written notes?
Milan Gardian
+1  A: 

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
jwmiller5
+1  A: 

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.

x0n
+1  A: 

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

Milan Gardian