11

I have scripted against sysocmgr in Windows XP, servermanagercmd in server 2008, and now I find that I have to use a new PowerShell module servermanager to install features on Server 2008 R2 and so I would expect that I would use the same module in Windows 7 but it's not there.

How can I install Windows features using the command line or PowerShell in Windows 7?

1
  • Time has finally provided a way using powershell, my answer is below.
    – MDMoore313
    Dec 19, 2013 at 15:04

7 Answers 7

12
dism.exe /online /?

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

2
  • 1
    specifically this MSDN page tells you to use a command like this: dism /online /Enable-Feature /FeatureName:{feature} use /Get-Features to list all available features. May 7, 2013 at 1:51
  • @EricFalsken This is now possible via powershell using the dism module.
    – MDMoore313
    Dec 19, 2013 at 15:03
6

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.

1
  • 1
    I was able to run Enable-WindowsOptionalFeature -FeatureName NetFx3 -Online on a Windows 8.1 machine without installing the AIK. I did, however, have the WMF5 preview installed; perhaps that provides it? The module is loaded from C:\windows\system32\windowspowershell\v1.0\Modules\Dism\Dism.psm1
    – bshacklett
    Mar 23, 2015 at 15:33
4

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.

2

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

import-module servermanager

get-windowsfeature

2
  • 1
    how would you add ServerManager feature separately?
    – fschwiet
    May 9, 2011 at 1:17
  • 2
    This would work for Windows 2008R2 and newer, but not for Windows 7.
    – Trondh
    May 16, 2013 at 19:01
2
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.

-1

For the Powershell part, open the 'Windows Powershell Modules' prompt and enter

PS1> Add-WindowsFeature [feature name]

eg

Add-WindowsFeature SMTP-Server

Get-WindowsFeature shows you the names of all the available features

2
  • 1
    I'm pretty sure this only works on Windows Server 2008 R2. Nov 9, 2009 at 20:34
  • Jeffery is correct, this does not work in windows 7 by default. If you know of a way to get it working I would like to know. Nov 9, 2009 at 21:15
-1

You could use a remote session from Windows 7 to a Windows Server 2008 R2 box and run Add-WindowsFeature. I have not been able to find it on Win7 even with RSAT installed.

1
  • 1
    Wouldn't that add the feature to the Windows Server 2008 R2 box and not to the local Windows 7 instance? If not please explain. Nov 9, 2009 at 21:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .