0
0
PowerShellscripting~15 mins

For loop in PowerShell - Mini Project: Build & Apply

Choose your learning style9 modes available
Using a For Loop in PowerShell
📖 Scenario: You are organizing a small event and have a list of guests. You want to greet each guest with a personalized message.
🎯 Goal: Build a PowerShell script that uses a for loop to print a greeting message for each guest in the list.
📋 What You'll Learn
Create an array of guest names
Create a variable to hold the number of guests
Use a for loop to iterate over the guest names
Print a greeting message for each guest
💡 Why This Matters
🌍 Real World
Automating repetitive tasks like sending personalized messages to a list of contacts.
💼 Career
Understanding loops is essential for scripting tasks in system administration, automation, and DevOps roles.
Progress0 / 4 steps
1
Create the guest list array
Create an array called guests with these exact names: "Alice", "Bob", "Charlie", "Diana".
PowerShell
Need a hint?

Use @() to create an array in PowerShell.

2
Create a variable for the number of guests
Create a variable called count that stores the number of guests in the guests array using the .Count property.
PowerShell
Need a hint?

Use $guests.Count to get the number of items in the array.

3
Write the for loop to greet each guest
Write a for loop that uses a variable i starting at 0 and runs while i is less than count. Inside the loop, access each guest by $guests[i].
PowerShell
Need a hint?

Use for ($i = 0; $i -lt $count; $i++) to loop through the array indexes.

4
Print greeting messages inside the loop
Inside the for loop, add a Write-Host statement to print: "Hello, $guest! Welcome to the event.".
PowerShell
Need a hint?

Use Write-Host to print messages in PowerShell.