Bird
0
0

Find the mistake in this code snippet:

medium📝 Debug Q7 of 15
PowerShell - Working with Objects
Find the mistake in this code snippet:
$obj = [PSCustomObject]@{Name='Lily'; Age=28}; $obj | Add-Member -Name Location -Value 'NY'
AMissing -MemberType parameter in Add-Member
BCannot pipe PSCustomObject to Add-Member
CAdd-Member syntax is correct, no mistake
DLocation property must be in hashtable initially
Step-by-Step Solution
Solution:
  1. Step 1: Review Add-Member usage

    Add-Member requires -MemberType parameter to specify property type.
  2. Step 2: Check code

    Code misses -MemberType, so it will error or not add property correctly.
  3. Step 3: Correct usage includes -MemberType NoteProperty

    Example: Add-Member -MemberType NoteProperty -Name Location -Value 'NY'
  4. Final Answer:

    Missing -MemberType parameter in Add-Member -> Option A
  5. Quick Check:

    Add-Member needs -MemberType = Missing -MemberType parameter in Add-Member [OK]
Quick Trick: Always specify -MemberType when using Add-Member [OK]
Common Mistakes:
  • Omitting -MemberType causes errors
  • Thinking piping PSCustomObject is invalid
  • Assuming properties must be pre-defined

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes