Recall & Review
beginner
What is a PSCustomObject in PowerShell?
A PSCustomObject is a way to create custom objects with properties and values in PowerShell. It helps organize data like a simple table or record.
Click to reveal answer
beginner
How do you create a PSCustomObject with properties Name and Age?
Use the syntax: <br>
$obj = [PSCustomObject]@{Name='Alice'; Age=30}<br>This creates an object with two properties: Name and Age.Click to reveal answer
intermediate
Why use PSCustomObject instead of a hashtable?
PSCustomObject lets you create objects that behave like real objects with properties, making it easier to work with in scripts and output. Hashtables are just key-value pairs without object behavior.
Click to reveal answer
intermediate
How can you add a new property to an existing PSCustomObject?
You can add a property by using
Add-Member cmdlet, for example:<br>$obj | Add-Member -NotePropertyName 'City' -NotePropertyValue 'Seattle'Click to reveal answer
beginner
What will this script output?<br>
$person = [PSCustomObject]@{Name='Bob'; Age=25}<br>$person.Age = 26<br>$personIt outputs the object with updated Age property:<br>
Name Age<br>---- ---<br>Bob 26<br>This shows you can change property values after creation.Click to reveal answer
Which syntax correctly creates a PSCustomObject with a property 'Color' set to 'Red'?
✗ Incorrect
Option D uses the correct syntax to create a PSCustomObject with the property Color set to Red.
How do you add a new property 'Country' with value 'USA' to an existing PSCustomObject $obj?
✗ Incorrect
Both A (direct property assignment) and C (using the Add-Member cmdlet) correctly add a new property to a PSCustomObject.
What type of data structure is a PSCustomObject in PowerShell?
✗ Incorrect
PSCustomObject is a custom object that holds properties and values, not just key-value pairs.
Which command updates the 'Age' property of a PSCustomObject $person to 40?
✗ Incorrect
You can directly assign a new value to an existing property using $person.Age = 40.
What happens if you try to create a PSCustomObject without using [PSCustomObject] type accelerator?
✗ Incorrect
Without [PSCustomObject], the syntax creates a hashtable, not a custom object.
Explain how to create a PSCustomObject with three properties and how to access one of those properties.
Think about how you write a hashtable and then convert it to an object.
You got /3 concepts.
Describe how to add a new property to an existing PSCustomObject and why this might be useful.
Remember you can modify objects after creation with a special cmdlet.
You got /3 concepts.