Bird
0
0

Which statement best explains why Add-Member -MemberType ScriptMethod uses $this inside the script block?

hard📝 Conceptual Q10 of 15
PowerShell - Working with Objects
Which statement best explains why Add-Member -MemberType ScriptMethod uses $this inside the script block?
A$this is a global variable holding all script methods
B$this is required to define parameters for the method
C$this refers to the object instance the method is attached to, allowing access to its properties
D$this automatically runs the script block when added
Step-by-Step Solution
Solution:
  1. Step 1: Understand $this in ScriptMethod context

    $this refers to the current object instance inside the script block, enabling access to its properties and methods.
  2. Step 2: Eliminate incorrect options

    $this is not a global variable, not for defining parameters, nor does it run the script automatically.
  3. Final Answer:

    $this refers to the object instance the method is attached to, allowing access to its properties -> Option C
  4. Quick Check:

    $this accesses object properties in ScriptMethod = B [OK]
Quick Trick: $this is the object inside ScriptMethod script blocks [OK]
Common Mistakes:
  • Thinking $this is global or unrelated
  • Confusing $this with parameter definition
  • Assuming $this triggers method execution

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes