Tracking installed roles, role services, and features
As discussed previously, you can determine the roles, roles
services, and features that are installed on a server by typing
get-windowsfeature
at a PowerShell prompt. Each installed role, role
service, and feature is highlighted and marked as such, with roles and
role services listed in the output before features as shown in the
following example:
Display Name Name Install State
------------ ---- -------------
[ ] Active Directory Certificate Services AD-Certificate Available
[ ] Certification Authority ADCS-Cert-Authority Available
[ ] Certificate Enrollment Policy Web Service ADCS-Enroll-Web-Pol Available
[ ] Certificate Enrollment Web Service ADCS-Enroll-Web-Svc Available
[ ] Certification Authority Web Enrollment ADCS-Web-Enrollment Available
[ ] Network Device Enrollment Service ADCS-Device-Enrollment Available
[ ] Online Responder ADCS-Online-Cert Available
[X] Active Directory Domain Services AD-Domain-Services Installed
...
[X] .NET Framework 4.5 Features NET-Framework-45-Fea... Installed
[X] .NET Framework 4.5 NET-Framework-45-Core Installed
[X] ASP.NET 4.5 NET-Framework-45-ASPNET Installed
[X] WCF Services NET-WCF-Services45 Installed
[ ] HTTP Activation NET-WCF-HTTP-Activat... Available
[ ] Message Queuing (MSMQ) Activation NET-WCF-MSMQ-Activat... Available
[ ] Named Pipe Activation NET-WCF-Pipe-Activat... Available
[X] TCP Activation NET-WCF-TCP-Activati... Installed
[X] TCP Port Sharing NET-WCF-TCP-PortShar... Installed
[ ] Background Intelligent Transfer Service (B... BITS Available
[ ] IIS Server Extension BITS-IIS-Ext Available
[ ] Compact Server BITS-Compact-Server Available
[ ] BitLocker Drive Encryption BitLocker Available
Because the –Name parameter, which allows
you to look for components with a specific name, accepts wildcards, you
can easily check the installation status and availability of related components. This
example returns a list of components with a management name that
starts with NET or
web:
get-windowsfeature -name net*, web*
Technically, you don’t need to include
–Name. The –Name parameter
is the first expected parameter. Thus, you could perform the previous
search by entering the following as well:
get-windowsfeature net*, web*
Because you won’t always be working with a local computer at the
prompt, you can use the –ComputerName parameter
to specify the name or IP address of the remote computer you want to
work with. In this example, you get the status of components on CorpServer18:
get-windowsfeature -computername corpserver18
For the purposes of documenting a server’s configuration, you
can save the output in a file as standard text using the redirection
symbol (>) as shown in this example:
get-windowsfeature > MySavedResults.txt
Here, you save the output to a file named MySavedResults.txt in
the current (working) directory.
Installing components at the prompt
You can install roles, role services, and features by typing Install-WindowsFeature
ComponentName
at an elevated prompt, where
ComponentName is the management name of the
component to install as listed in Table 3 or Table 4. In the
following example, you install DHCP Server and the DHCP console for
managing DHCP Server on CorpServer15:
Install-windowsfeature dhcp -ComputerName corpserver15 -includemanagementtools
Here, you don’t need to include the
–IncludeAllSubFeature parameter because DHCP
Server doesn’t have any subordinate role services or features. As
PowerShell works, you see a Start Installation progress bar. When
the installation is complete, you see the result. The output for a
successful installation should look similar to the
following:
Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True No Success {DHCP Server}
As you can see, the output specifies whether the installation
was successful, whether a restart is needed, an exit code, and a
list of the exact change or changes made. The exit code can be
different from the Success status. For example, if the components
you specify are already installed, the exit code is NoChangeNeeded,
as shown in this example and sample output:
Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True No NoChangeNeeded {}
Here, you see that Install-WindowsFeature was successful but didn’t
actually make any changes. The Feature Result shows no changes as
well.
You don’t have to explicitly name the component or components you want to install. Install-WindowsFeature
accepts redirected output for component names, allowing you to use
another command to get the name or names of the components you want
to work with. For example, if you want to install multiple
components, such as all .NET components across the multiple .NET
Frameworks that are available, you could use Get-WindowsFeature to help you do this, as shown in
the following example:
get-windowsfeature -name NET-* | install-windowsfeature
Here, you use Get-WindowsFeature to obtain a list of
components with names that start with NET– and then pipe that list
to Install-WindowsFeature. The result is that you install all .NET
components across all available .NET frameworks.
Component installation doesn’t always succeed, and
that’s a common reason that the server cannot be accessed, as shown
in this example, with accompanying error text:
Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
False Maybe Failed {}
install-windowsfeature : WinRM cannot process the request. The following error
occurred while using Kerberos authentication: Cannot find the computer
corpserver15. Verify that the computer exists on the network and that the
name provided is spelled correctly.
Here, Windows Remote Management (WinRM) couldn’t connect to
the remote computer. Typically, this occurs because the server is
offline or otherwise unavailable. This also could occur if you
entered an incorrect server name.
Inadequate user rights is another common reason for component installation to fail, as shown in this example, with
accompanying error text:
install-windowsfeature : You do not have adequate user rights to make changes to
the target computer. If you are already a member of the Administrators group on
the target computer, the changes might have failed because of security restrictions
imposed by User Account Control. Try running Install-WindowsFeature in a Windows
PowerShell session that has been opened with elevated rights (Run as administrator).
Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
False No Failed {}
Normally, when you are using Windows PowerShell for
administration, you’ll use an elevated, administrator prompt and
your current credentials will pass through to remote computers you
work with. However, if your account doesn’t have appropriate user
rights, you need to provide different credentials and you can do
this using the –Credential parameter. You’ll be
prompted for the user’s password if you follow the
–Credential parameter with a user name, as
shown in this example:
Install-windowsfeature dns -credential "CPANDL\wrstanek" -includemanagementtools
Here, you simply type the password and press Enter when
prompted to run the command with the named account’s permissions.
Rather than enter credentials for an account each time you want to
perform administration, you can store credentials and then refer to the stored credential, as shown in this example:
$cred = get-credential
install-windowsfeature dns -credential $cred -includemanagementtools
Here, you use Get-Credential to prompt for a user name and
password, and then store those credentials in the
$cred variable. Next, you refer to the stored
credentials to install DNS. Because the credentials are stored for
the duration of your current PowerShell session, you can refer to
them as needed for additional administration as well.
To test the installation prior to performing that actual
operation, you can use the –Whatif parameter, as shown in the following example:
get-windowsfeature -name BIT* | install-windowsfeature -whatif
If you run this command, you might be surprised to see that
BitLocker components are included along with BITS components. To resolve this, you need to be more
specific when specifying the component name to match. If you intend to install
BitLocker and BitLocker Network Unlock, you can use the following
command instead:
get-windowsfeature -name bitlock* | install-windowsfeature -whatif
If a restart is required to complete an installation, you can
have Install-WindowsFeature restart the computer by including the
–Restart parameter. For planning purposes,
especially on highly active production servers, keep in mind that
both successful and failed installations could require a
restart.
Removing components at the prompt
You can uninstall roles, role services, and features by typing Uninstall-ServerManager
ComponentName
at an elevated command prompt, where
ComponentName is the name of the component to
uninstall as listed in Table 3 or Table 4. Because
Uninstall-ServerManager automatically uninstalls any subordinate
role services and features of the specified component, you normally
want to test the uninstallation prior to performing that actual
operation. To do this, you can use the –Whatif
parameter, as shown in the following example:
uninstall-windowsfeature net-framework-45-features -whatif
Here, you want to uninstall .NET Framework 4.5 and related
features, which include .NET Framework 4.5 (NET-Framework-45-Core),
ASP.NET 4.5 (NET-Framework-45-ASPNET), and multiple subcomponents of
WCF Services (NET-WCF-Services45). However, if you want to uninstall
only the WCF Services, you enter the following instead:
uninstall-windowsfeature net-wcf-services45
As with Install-WindowsFeature, you don’t have to explicitly
name the component or components you want to uninstall.
Uninstall-WindowsFeature accepts redirected output for component
names, allowing you to use another command to get the name or names
of the components you want to work with. For example, if you want to
uninstall multiple components, such as all .NET components across
the multiple .NET Frameworks that are available, you could use
Get-WindowsFeature to help you do this, as shown in the following
example:
get-windowsfeature -name NET-* | uninstall-windowsfeature
To ensure that the command works exactly as expected, you
should test the command first using the –Whatif
parameter, as shown in the following example:
get-windowsfeature -name NET-* | uninstall-windowsfeature -whatif
As with installing components, the command output specifies if
a restart is required to complete the task. If a restart is required
to complete a removal, you can have Uninstall-WindowsFeature restart
the computer by including the –Restart
parameter.
If an error occurs and Uninstall-WindowsFeature is not able to
perform the operation specified, you’ll see an error.