Bird
0
0

What issue will occur when running this code?

medium📝 Debug Q6 of 15
PowerShell - Working with Objects
What issue will occur when running this code?
$obj = New-Object PSObject
Add-Member -InputObject $obj -MemberType NoteProperty -Name Level -Value 1
Add-Member -InputObject $obj -MemberType NoteProperty -Name Level -Value 2
AThe property 'Level' is updated to 2 without error
BAn error occurs because the property 'Level' already exists
CTwo properties named 'Level' are added successfully
DThe script runs but the first property is ignored
Step-by-Step Solution
Solution:
  1. Step 1: Analyze property addition

    The first Add-Member adds a NoteProperty 'Level' with value 1.
  2. Step 2: Adding duplicate property

    Attempting to add another NoteProperty with the same name 'Level' without using -Force causes an error.
  3. Final Answer:

    An error occurs because the property 'Level' already exists -> Option B
  4. Quick Check:

    Duplicate property names cause errors [OK]
Quick Trick: Duplicate property names cause errors unless -Force used [OK]
Common Mistakes:
  • Assuming property value updates automatically
  • Expecting multiple properties with same name
  • Ignoring the need for -Force to overwrite

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes