Bird
0
0

Which of the following is a correct example of using the -replace operator in PowerShell?

easy📝 Conceptual Q2 of 15
PowerShell - Regular Expressions
Which of the following is a correct example of using the -replace operator in PowerShell?
A'PowerShell' -replace
B'PowerShell' -replace 'Shell'
C'PowerShell' -replace 'Shell',
D'PowerShell' -replace 'Shell', 'Script'
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax

    The -replace operator requires two arguments: the pattern and the replacement string.
  2. Step 2: Validate options

    'PowerShell' -replace 'Shell', 'Script' correctly provides both arguments. Options B, C, and D are incomplete or invalid.
  3. Final Answer:

    'PowerShell' -replace 'Shell', 'Script' -> Option D
  4. Quick Check:

    Are both pattern and replacement provided? [OK]
Quick Trick: Replace needs pattern and replacement strings [OK]
Common Mistakes:
  • Omitting replacement string
  • Leaving trailing commas
  • Using incomplete syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes