DCSIMG
PSClientManager – PowerShell module to Add/Remove Windows 7 features - Shay Levy

Shay Levy

If you repeat it, PowerShell it!

PSClientManager – PowerShell module to Add/Remove Windows 7 features

PSClientManager Windows Server 2008 R2 includes a  PowerShell module, ServerManager, for managing server roles, role services, and features via PowerShell cmdlets. In Windows 7, there is no such module and we need to use the GUI  (OptionalFeatures.exe) or the ‘Deployment Image Servicing and Management’ tool (DISM, see list of resources below).
The problem with DISM, from a PowerShell perspective (objects, objects…), is that DISM is a legacy application that emits text and is not written with automation in mind .

 

 

PSClientManager is a PowerShell module that takes advantage of DISM and automates the task of adding and removing optional OS features by using four Advanced Functions. Each function runs DISM, parse its output and converts the result to custom objects.

  • Add-ClientFeature
  • Get-ClientFeature
  • Get-ClientFeatureInfo
  • Remove-ClientFeature

 

To get a quick look at all the the available features on your system, run the Get-ClientFeature without any parameters. One of the first features a system administrator would want to install is Telnet. Lets see how we can find and install it. We will run the Get-ClientFeature command and use a wildcard pattern for the feature name parameter.
 
 

PS > Get-ClientFeature –Name *telnet* | Format-Table -AutoSize

Name State
---- ------
TelnetServer Disabled
TelnetClient Disabled
 

The result shows that there are two Telnet features, Client and Server, and both are disabled. Lets get some more information about the client feature:

PS > Get-ClientFeatureInfo –Name TelnetClient

Name : TelnetClient
DisplayName : Telnet Client
RestartRequired : Possible
Properties :
Description : Connect to remote computers by using the Telnet protocol
State : Disabled

 

Now let’s enable it. Adding or removing features changes the system so the command asks for confirmation. To suppress confirmations use the –Force parameter or ‘-Confirm:$false’:

PS > Add-ClientFeature –Name TelnetClient

Confirm
Are you sure you want to perform this action?
Performing operation "Enable Feature 'TelnetClient'" on Target "PC1".
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): y

Deployment Image Servicing and Management tool
Version: 6.1.7600.16385

Image Version: 6.1.7600.16385

Enabling feature(s)
[==========================100.0%==========================]
The operation completed successfully.

 

 

We can verify that the Telnet has been enabled by running the Get-ClientFeatureInfo or Get-ClientFeature.

PS > Get-ClientFeatureInfo –Name TelnetClient

Name : TelnetClient
DisplayName : Telnet Client
RestartRequired : Possible
Properties :
Description : Connect to remote computers by using the Telnet protocol
State : Enabled


PS > Get-ClientFeature Telnet* | Format-Table -AutoSize

Name State
---- ------
TelnetServer Disabled
TelnetClient Enabled

 

The functions can also pipe feature object(s) from one command to another. For example, the following command enables the Telnet client and server features on the current system (check help for a complete list of command parameters and code examples):

PS > Get-ClientFeature tel* | Add-ClientFeature 

Gotcha: Feature names are case sensitive! Make sure you write them with the proper case.

 

The PSClientManager module is available for download at MSDN Code Gallery in two forms, a zip file containing the source files or as an MSI package.

 

DISM Resources

Comments

Twitter Trackbacks for PSClientManager ??? PowerShell module to Add/Remove Windows 7 features - Shay Levy [microsoft.co.il] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 PSClientManager ??? PowerShell module to Add/Remove Windows 7 features - Shay Levy         [microsoft.co.il]        on Topsy.com

# April 25, 2010 10:58 AM

Bhargav Shukla said:

Shouldn't

"Enable-ClientFeature –Name TelnetClient"

read

"Add-ClientFeature –Name TelnetClient"?

# April 28, 2010 6:34 PM

ScriptFanatic said:

Indeed, thanks for reporting it!

# April 28, 2010 6:41 PM

Episode 111 – Buck Woody from Microsoft on SQL Server and PowerShell « PowerScripting Podcast said:

Pingback from  Episode 111 – Buck Woody from Microsoft on SQL Server and PowerShell «  PowerScripting Podcast

# May 4, 2010 6:11 AM

Howard Gyton said:

Hi,

Just started using the useful module but found a possible problem.

When trying to run a simple script such as:

Import-Module PSClientManager

Add-ClientFeature TelnetClient

It always fails. However if I insert a 'Get-ClientFeature' as below:

Import-Module PSClientManager

Get-ClientFeature <any feature will do here>

Add-ClientFeature TelnetClient

Then it always works. It only seems to fail with an 'Add', a 'Remove' will work without using 'Get'.

It seems to behave like this whether run from outside or inside Powershell.

Is this a bug perhaps?

# November 20, 2010 5:53 PM

ScriptFanatic said:

Thanks for reporting this Howard, I fixed the bug and replaced the installation files on the module download page. Can you please re-install the module and confirm that the issue no longer exists?

-Shay

# November 21, 2010 12:06 PM

Howard Gyton said:

Yes, the issue has been resolved.

Thanks!

# November 21, 2010 2:04 PM

Simon Burbery said:

Hi, this is great however I cannot work out how to add / remove a feature with a space in the name!  What am I missing?

e.g. Remove-ClientFeature -Name "More Games" -Force

I have tried brackets etc but no luck.

Thanks for a great tool!

Simon

# April 3, 2012 7:29 AM

ScriptFanatic said:

Thanks for the feedback @Simon, you've just found a bug in the module :)

To fix it, locate this line in the Remove-ClientFeature and Add-ClientFeature functions (it's in the module psm1 file):

$dism = "DISM /Online /Disable-Feature /FeatureName:$Name"

And enclose single the $Name variable with single quotes.

$dism = "DISM /Online /Disable-Feature /FeatureName:'$Name'"

I will upload a new version to codeplex with this fix.

# April 3, 2012 5:22 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: