Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Windows Features Management with PowerShell
📖 Scenario: You are managing a Windows server and need to check which Windows features are installed, decide which features to install or remove, and then apply those changes using PowerShell scripts.
🎯 Goal: Build a PowerShell script that lists installed Windows features, sets a feature to install or remove based on a configuration, applies the change, and then shows the updated feature status.
📋 What You'll Learn
Use PowerShell commands to list Windows features
Create a variable to hold the feature name to manage
Use conditional logic to install or remove the feature
Display the final status of the feature
💡 Why This Matters
🌍 Real World
System administrators often need to automate the management of Windows features to keep servers optimized and secure.
💼 Career
Knowing how to script Windows feature management is valuable for IT support, system administration, and automation roles.
Progress0 / 4 steps
1
List Installed Windows Features
Write a PowerShell command to get all Windows features and store them in a variable called features.
PowerShell
Hint
Use the Get-WindowsFeature cmdlet to list all features.
2
Set Feature to Manage
Create a variable called featureName and set it to the string 'Telnet-Client' to specify the feature you want to manage.
PowerShell
Hint
Assign the feature name as a string to the variable featureName.
3
Install or Remove the Feature
Write an if statement that checks if the feature named featureName is installed by looking in $features. If it is installed, remove it using Remove-WindowsFeature. If it is not installed, install it using Install-WindowsFeature.
PowerShell
Hint
Use Where-Object to find the feature by name and check its Installed property.
4
Display Updated Feature Status
Run Get-WindowsFeature again for the feature named featureName and print its name and installation status using Write-Output.
PowerShell
Hint
Use Get-WindowsFeature -Name $featureName and Write-Output to show the feature status.
Practice
(1/5)
1. What does the PowerShell cmdlet Get-WindowsFeature do?
easy
A. Restarts the computer after feature changes
B. Installs a new Windows feature
C. Lists all available Windows features and their installation status
D. Removes an installed Windows feature
Solution
Step 1: Understand the cmdlet purpose
Get-WindowsFeature is used to view Windows features, not change them.
Step 2: Identify the correct description
This cmdlet lists all features and shows if they are installed or not.
Final Answer:
Lists all available Windows features and their installation status -> Option C
Quick Check:
Get-WindowsFeature = List features [OK]
Hint: Get-WindowsFeature always shows features, never installs or removes [OK]
Common Mistakes:
Confusing Get-WindowsFeature with Install-WindowsFeature
Thinking it restarts the system
Assuming it removes features
2. Which of the following is the correct syntax to install the Windows feature named 'Web-Server' using PowerShell?
easy
A. Enable-WindowsFeature -Feature Web-Server
B. Get-WindowsFeature -Install Web-Server
C. Add-WindowsFeature Web-Server
D. Install-WindowsFeature -Name Web-Server
Solution
Step 1: Identify the cmdlet for installing features
The correct cmdlet to install a feature is Install-WindowsFeature.
Step 2: Check the parameter usage
The feature name is passed with the -Name parameter, so Install-WindowsFeature -Name Web-Server is correct.
Final Answer:
Install-WindowsFeature -Name Web-Server -> Option D
A. The feature name is incorrect or does not exist on this system
B. You need to run PowerShell as a normal user, not admin
C. Uninstall-WindowsFeature cannot remove features, only disables them
D. The command syntax is missing the -Force parameter
Solution
Step 1: Analyze the error cause
The error likely occurs because the feature name "NonExistentFeature" is not valid or not installed on the system.
Step 2: Check other options
Uninstalling requires administrator privileges, but the error would specify permissions if that were the issue. The cmdlet does remove installed features. The -Force parameter is optional and not required for non-existent features.
Final Answer:
The feature name is incorrect or does not exist on this system -> Option A
Quick Check:
Invalid feature name = error [OK]
Hint: Check feature name spelling and existence before uninstalling [OK]
Common Mistakes:
Running PowerShell without admin rights
Assuming uninstall cmdlet disables only
Adding unnecessary parameters like -Force
5. You want to write a script that installs multiple Windows features: 'Web-Server', 'Telnet-Client', and 'RSAT'. Which is the best PowerShell approach?
hard
A. Use a loop with Install-WindowsFeature for each feature name in an array
B. Run Install-WindowsFeature once with all feature names separated by commas
C. Run Get-WindowsFeature and pipe output to Install-WindowsFeature
D. Use Uninstall-WindowsFeature first, then Install-WindowsFeature for each feature
Solution
Step 1: Understand installing multiple features
PowerShell's Install-WindowsFeature accepts multiple feature names as a comma-separated list in the -Name parameter, but it is recommended to use a loop for clarity and error handling.
Step 2: Evaluate options
A loop with Install-WindowsFeature for each feature name in an array is the best approach for scripting multiple installs. Running once with all names separated by commas is possible but less flexible. Piping Get-WindowsFeature output would attempt to install all features, which is dangerous. Using Uninstall-WindowsFeature first is inefficient and risky.
Final Answer:
Use a loop with Install-WindowsFeature for each feature name in an array -> Option A
Quick Check:
Looping Install-WindowsFeature for each feature = best practice [OK]
Hint: Use a loop to install multiple features individually for better control [OK]
Common Mistakes:
Using a single command with comma-separated names without error handling
Piping Get-WindowsFeature output to install all features
Uninstalling features before installing unnecessarily