0
0
PowerShellscripting~15 mins

Arrays in PowerShell - Mini Project: Build & Apply

Choose your learning style9 modes available
Working with Arrays in PowerShell
📖 Scenario: You are organizing a small event and need to manage a list of guest names using PowerShell arrays.
🎯 Goal: Build a PowerShell script that creates an array of guest names, adds a new guest, filters guests whose names start with a specific letter, and then displays the filtered list.
📋 What You'll Learn
Create an array with exact guest names
Add a new guest name to the array
Filter the array for names starting with a specific letter
Print the filtered list of guest names
💡 Why This Matters
🌍 Real World
Managing lists of items like guest names, file names, or tasks is common in automation scripts.
💼 Career
Knowing how to work with arrays and filter data is essential for system administrators and automation engineers.
Progress0 / 4 steps
1
Create the initial array of guest names
Create an array called guests with these exact names: "Alice", "Bob", "Charlie", "Diana", and "Ethan".
PowerShell
Need a hint?

Use @() to create an array and separate names with commas.

2
Add a new guest name to the array
Add the guest name "Fiona" to the existing guests array using the += operator.
PowerShell
Need a hint?

Use $guests += "Fiona" to add a new item to the array.

3
Filter guests whose names start with the letter 'C'
Create a new array called filteredGuests that contains only the names from guests starting with the letter 'C'. Use the Where-Object cmdlet with a script block checking if the name starts with 'C'.
PowerShell
Need a hint?

Use Where-Object { $_.StartsWith('C') } to filter names starting with 'C'.

4
Display the filtered guest names
Print the contents of the filteredGuests array using Write-Output.
PowerShell
Need a hint?

Use Write-Output $filteredGuests to display the filtered names.