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?
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 inand you can just point powershell to that folder with
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
That will return a
Microsoft.DISM.Commands.BasicFeatureObject
, as seen here. From there, you can set thestate
property to disabled, likeand 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:
dism
is the only way I've found that works.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.
Add ServerManager-feature manually. Then you can add servermanager-module:
import-module servermanager
get-windowsfeature
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
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.