How do I turn windows features on or off using powershell or commandline in windows 7?

dism.exe /online /?

also, check out http://www.windowsnetworking.com/articles_tutorials/Deploying-Windows-7-Part2.html


For a true powershell experience, you need to download the Windows AIK for 8.0 and use the dism module. It's found in

C:\Program Files (x86)\Windows Kits\8.0\Assessment and Deployment Kit\Deployment Tools\<arch>\DISM

and you can just point powershell to that folder with

Import-Module C:\Program Files (x86)\Windows Kits\8.0\Assessment and Deployment Kit\Deployment Tools\<arch>\DISM

Make sure you replace < arch > with the architecture of the machine powershell is running on. That DISM folder can even be copied and redistributed to machines if need be (speaking on functionality, I don't know if redistributing is actually allowed by Microsoft).

The specific command to toss out a Windows optional feature is

Get-WindowsOptionalFeature -Online | where FeatureName -eq mediacenter

That will return a Microsoft.DISM.Commands.BasicFeatureObject, as seen here. From there, you can set the state property to disabled, like

$(Get-WindowsOptionalFeature -Online | where FeatureName -eq mediacenter).state = 
    [Microsoft.DISM.Commands.FeatureState]::Disabled

and bye bye media center. Of course, this has to be run from an elevated prompt, and the -Online switch refers to the current running Windows, as opposed to an offline image.

Also, this module requires WMF 3.0 and that requires .NET 4.0, just FYI.


Attempting to run the PowerShell from Windows 7/8 will only get you this:

Get-WindowsFeature : The target of the specified cmdlet cannot be a Windows client-based operating system.

dism is the only way I've found that works.


Add ServerManager-feature manually. Then you can add servermanager-module:

import-module servermanager

get-windowsfeature


ocsetup.exe /?

In addition to dism it appears you can also use ocsetup which is installed by default on Windows Vista and Windows Server 2008. If you were looking to script something that works across all three of these then this would probably be the way to go.