PSClientManager – PowerShell module to Add/Remove Windows 7 features
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