0
0
PowerShellscripting~30 mins

Hash tables (dictionaries) in PowerShell - Mini Project: Build & Apply

Choose your learning style9 modes available
Working with Hash Tables (Dictionaries) in PowerShell
📖 Scenario: You are managing a small store's inventory. You want to keep track of product names and their quantities using a hash table in PowerShell.
🎯 Goal: Build a PowerShell script that creates a hash table for products and quantities, sets a minimum stock threshold, filters products below that threshold, and displays those products.
📋 What You'll Learn
Create a hash table named inventory with exact product names and quantities
Create a variable named minStock with a numeric value
Use a foreach loop to find products with quantity less than minStock
Store filtered products in a new hash table named lowStock
Print the lowStock hash table at the end
💡 Why This Matters
🌍 Real World
Managing inventory levels in small businesses or stores to know when to reorder products.
💼 Career
PowerShell scripting for system administrators or IT professionals automating inventory or configuration tasks.
Progress0 / 4 steps
1
Create the inventory hash table
Create a hash table called inventory with these exact entries: 'Apples' = 30, 'Bananas' = 12, 'Oranges' = 20, 'Grapes' = 5
PowerShell
Need a hint?

Use @{} to create a hash table in PowerShell. Separate entries with semicolons.

2
Set the minimum stock threshold
Create a variable called minStock and set it to 15
PowerShell
Need a hint?

Just assign the number 15 to the variable minStock.

3
Find products with low stock
Create an empty hash table called lowStock. Use a foreach loop with variables product and quantity to iterate over $inventory.GetEnumerator(). Inside the loop, if quantity is less than minStock, add the product and quantity to lowStock.
PowerShell
Need a hint?

Use $inventory.GetEnumerator() to loop through the hash table. Use $lowStock[$product] = $quantity to add entries.

4
Display the low stock products
Print the lowStock hash table using Write-Output
PowerShell
Need a hint?

Use Write-Output $lowStock to display the hash table.