Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Time has finally provided a way using powershell, my answer is below. –  BigHomie Dec 19 '13 at 15:04
add comment

7 Answers

up vote 7 down vote accepted
dism.exe /online /?

also, check out http://www.windowsnetworking.com/articles%5Ftutorials/Deploying-Windows-7-Part2.html

share|improve this answer
    
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. –  Eric Falsken May 7 '13 at 1:51
    
@EricFalsken This is now possible via powershell using the dism module. –  BigHomie Dec 19 '13 at 15:03
add comment

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

import-module servermanager

get-windowsfeature

share|improve this answer
1  
how would you add ServerManager feature separately? –  fschwiet May 9 '11 at 1:17
1  
This would work for Windows 2008R2 and newer, but not for Windows 7. –  Trondh May 16 '13 at 19:01
add comment
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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
    
I'm pretty sure this only works on Windows Server 2008 R2. –  Jeffery Hicks Nov 9 '09 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. –  Chris Magnuson Nov 9 '09 at 21:15
add comment

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.

share|improve this answer
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. –  Chris Magnuson Nov 9 '09 at 21:16
add comment

protected by Tom O'Connor Sep 12 '13 at 9:49

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.