PowerShell - Working with ObjectsHow can you create a custom object in PowerShell with properties 'Name' and 'Age'?A$person = New-Object Name, AgeB$person = [PSCustomObject]@{Name='Alice'; Age=30}C$person = @{Name='Alice'; Age=30}D$person = Object(Name='Alice', Age=30)Check Answer
Step-by-Step SolutionSolution:Step 1: Understand custom object creationUse [PSCustomObject] with a hashtable to create objects with properties.Step 2: Check syntax correctness$person = [PSCustomObject]@{Name='Alice'; Age=30} correctly uses [PSCustomObject] and a hashtable with Name and Age.Final Answer:$person = [PSCustomObject]@{Name='Alice'; Age=30} -> Option BQuick Check:Custom object creation = A [OK]Quick Trick: Use [PSCustomObject] with @{ } to create objects with properties [OK]Common Mistakes:Using New-Object incorrectlyConfusing hashtables with objectsUsing invalid syntax for object creation
Master "Working with Objects" in PowerShell9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PowerShell Quizzes Error Handling - ErrorAction parameter - Quiz 11easy File and Directory Operations - Test-Path for existence checks - Quiz 1easy File and Directory Operations - Writing files (Set-Content, Out-File) - Quiz 1easy File and Directory Operations - Why file management is core to scripting - Quiz 13medium File and Directory Operations - CSV operations (Import-Csv, Export-Csv) - Quiz 6medium Modules and Script Organization - Why modules package reusable code - Quiz 6medium Regular Expressions - match operator - Quiz 12easy Regular Expressions - match operator - Quiz 15hard Regular Expressions - Why regex enables pattern matching - Quiz 15hard Working with Objects - Measure-Object for statistics - Quiz 6medium