Recall & Review
beginner
What is a hash table in PowerShell?
A hash table is a collection of key-value pairs. It lets you store and quickly find data by using a unique key, like a labeled box for your information.
Click to reveal answer
beginner
How do you create an empty hash table in PowerShell?
You create an empty hash table using @{} like this: <br>
$myHash = @{}Click to reveal answer
beginner
How do you add a key-value pair to a hash table?
Use the syntax: <br>
$hashTable["key"] = "value"<br>This adds or updates the value for the given key.Click to reveal answer
beginner
How do you access a value from a hash table by its key?
Use the key inside square brackets: <br>
$value = $hashTable["key"]<br>This gets the value stored for that key.Click to reveal answer
beginner
What happens if you try to access a key that does not exist in a hash table?
PowerShell returns nothing (null). It does not cause an error, but you get no value back.
Click to reveal answer
Which symbol is used to create a hash table in PowerShell?
✗ Incorrect
The @{} syntax creates a hash table in PowerShell.
How do you add a new key 'Name' with value 'Alice' to a hash table $h?
✗ Incorrect
In PowerShell, you add or update a key-value pair using $h['Name'] = 'Alice'.
What does $h['Age'] return if 'Age' is not a key in $h?
✗ Incorrect
Accessing a missing key returns null, not an error.
How do you create a hash table with keys 'City' and 'Country' and values 'Paris' and 'France'?
✗ Incorrect
The correct syntax uses @{} with semicolons separating key-value pairs.
Which of these is NOT a valid way to access a hash table value?
✗ Incorrect
PowerShell does not use '->' to access hash table items.
Explain how to create, add to, and retrieve data from a hash table in PowerShell.
Think of a hash table as a labeled box where you put and get items by their labels.
You got /3 concepts.
What happens when you try to get a value from a hash table using a key that does not exist? How can this behavior be useful?
Consider how you might safely check for data without breaking your script.
You got /3 concepts.