How to Install Windows Features with PowerShell?


To install windows features on the server, Install-WindowsFeature cmdlet is used .

Install-WindowsFeature Windows-Server-Backup -LogPath C:\Temp\Installfeatures.txt -Verbose

In the above example, Windows-Server-Backup feature will be installed on the local server and logs will be stored at location C:\Temp and file name InstallFeatures.txt.

PS C:\Users\Administrator> Install-WindowsFeature Windows-Server-Backup -LogPath C:\Temp\Installfeatures.txt -Verbose
VERBOSE: Installation started...
VERBOSE: Continue with installation?
VERBOSE: Prerequisite processing started...
VERBOSE: Prerequisite processing succeeded.
Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True No Success {Windows Server Backup}
VERBOSE: Installation succeeded.

You can also install the feature with the pipeline command,

Get-WindowsFeature Windows-server-backup | Install-WindowsFeature -LogPath C:\Temp\Installfeatures.txt -Verbose

If your windows feature includes the sub-features like in the case of Web-Server (IIS) and which also needs management tools.

For the above scenario, we will use -IncludeAllSubFeature to include roles and -IncludeManagementTools to install management tools.

Install-WindowsFeature Web-Server -IncludeAllSubFeature -IncludeManagementTools -Source -Verbose

When you install any feature and don’t provide any source path then make sure your windows operating system disk related to that particular OS should be loaded otherwise there will an error generated for the source path.

Install-WindowsFeature Web-Server -IncludeAllSubFeature -IncludeManagementTools -verbose VERBOSE: Installation started...
VERBOSE: Continue with installation?
VERBOSE: Prerequisite processing started...
VERBOSE: Prerequisite processing succeeded.

Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True No Success {Application Development, Application Init...
VERBOSE: Installation succeeded.

If the OS disk is not mounted then you need to copy the SXS folder under Source directory from the related operating system CD and provide that directory as the source path. For example,

Install-WindowsFeature Web-Server -IncludeAllSubFeature -IncludeManagementTools -Source C:\Temp\sxs\ -Verbose
PS C:\Users\Administrator> Install-WindowsFeature Web-Server -IncludeAllSubFeature -IncludeManagementTools -Source C:\Temp\sxs\ -Verbose VERBOSE: Installation started...
VERBOSE: Continue with installation?
VERBOSE: Prerequisite processing started...
VERBOSE: Prerequisite processing succeeded.

Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True No Success {Application Development, Application Init.
..
VERBOSE: Installation succeeded.

This -Name parameter supports multiple features. So we can install multiple features together like GUI.

help Install-WindowsFeature -Parameter Name -Name <Feature[]>

For example,

Install-WindowsFeature -Name Telnet-Client, Search-Service -Verbose

Output

Install-WindowsFeature -Name Telnet-Client, Search-Service -Verbose
VERBOSE: Installation started...
VERBOSE: Continue with installation?
VERBOSE: Prerequisite processing started...
VERBOSE: Prerequisite processing succeeded.
Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True No Success {Windows Search Service, Telnet Client}
VERBOSE: Installation succeeded.

To install windows features on the remote computer, you can use -ComputerName parameter. For example,

Install-WindowsFeature Telnet-Client -ComputerName Test1-Win2k16 -Verbose

Output

VERBOSE: Installation started...
VERBOSE: Continue with installation?
VERBOSE: Prerequisite processing started...
VERBOSE: Prerequisite processing succeeded.
Success Restart Needed Exit Code Feature Result
------- -------------- --------- --------------
True No Success {Telnet Client}
VERBOSE: Installation succeeded.

If we check the allowed datatype for the -ComputerName parameter then it is a string type, not the array so we can pass only one computer Name.

PS C:\Users\Administrator > help Install-WindowsFeature -Parameter ComputerName -ComputerName [<String>]

So to install features on multiple computers, either we need to loop the -ComputerName using foreach loop or you can use Invoke-Command method. For convenience, we will use the later method.

Invoke-Command -ComputerName Test1-Win2k12, Test1-Win2k16 -ScriptBlock{Install-WindowsFeature Telnet-Client}

Updated on: 26-Aug-2020

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements