Bird
0
0

You want to write a script that installs multiple Windows features: 'Web-Server', 'Telnet-Client', and 'RSAT'. Which is the best PowerShell approach?

hard📝 Application Q15 of 15
PowerShell - System Administration
You want to write a script that installs multiple Windows features: 'Web-Server', 'Telnet-Client', and 'RSAT'. Which is the best PowerShell approach?
AUse a loop with Install-WindowsFeature for each feature name in an array
BRun Install-WindowsFeature once with all feature names separated by commas
CRun Get-WindowsFeature and pipe output to Install-WindowsFeature
DUse Uninstall-WindowsFeature first, then Install-WindowsFeature for each feature
Step-by-Step Solution
Solution:
  1. 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.
  2. 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.
  3. Final Answer:

    Use a loop with Install-WindowsFeature for each feature name in an array -> Option A
  4. Quick Check:

    Looping Install-WindowsFeature for each feature = best practice [OK]
Quick Trick: 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

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes