PowerShell - Working with ObjectsWhat happens if you add two NoteProperties with the same name to a PowerShell object without using -Force?ABoth properties exist with the same name and different valuesBThe second property overwrites the first silentlyCPowerShell throws an error and does not add the second propertyDThe object duplicates and creates two separate objectsCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand behavior of duplicate property namesWithout -Force, adding a property with an existing name causes an error.Step 2: Confirm other options are incorrectPowerShell does not silently overwrite without -Force, nor does it allow duplicate property names or duplicate objects.Final Answer:PowerShell throws an error and does not add the second property -> Option CQuick Check:Duplicate property without -Force causes error [OK]Quick Trick: Use -Force to overwrite existing properties, else error occurs [OK]Common Mistakes:Assuming silent overwrite without -ForceThinking duplicate properties can coexist
Master "Working with Objects" in PowerShell9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PowerShell Quizzes Error Handling - $Error automatic variable - Quiz 5medium Error Handling - ErrorAction parameter - Quiz 14medium Error Handling - Throw statement - Quiz 9hard File and Directory Operations - Remove-Item - Quiz 8hard File and Directory Operations - Get-ChildItem for listing - Quiz 2easy File and Directory Operations - Writing files (Set-Content, Out-File) - Quiz 1easy Functions - Why functions organize scripts - Quiz 13medium Working with Objects - Compare-Object for differences - Quiz 13medium Working with Objects - Object arrays - Quiz 10hard Working with Objects - Compare-Object for differences - Quiz 1easy