0
0
PowerShellscripting~15 mins

ForEach loop in PowerShell - Mini Project: Build & Apply

Choose your learning style9 modes available
Using ForEach Loop in PowerShell
📖 Scenario: You work in an office where you need to send a thank you message to a list of clients after a meeting.
🎯 Goal: You will create a list of client names, then use a ForEach loop to prepare a thank you message for each client.
📋 What You'll Learn
Create a list of client names in a variable called clients
Create a variable called message with the text 'Thank you for attending the meeting!'
Use a ForEach loop with the variable client to go through each name in clients
Inside the loop, create a personalized message combining client and message
Print each personalized message
💡 Why This Matters
🌍 Real World
Sending personalized messages or emails to a list of contacts is common in offices and customer service.
💼 Career
Knowing how to automate repetitive tasks like messaging clients saves time and reduces errors in many jobs.
Progress0 / 4 steps
1
Create the list of clients
Create a variable called clients and assign it a list with these exact names: 'Alice', 'Bob', 'Charlie'.
PowerShell
Need a hint?

Use @(...) to create a list (array) in PowerShell.

2
Add the message variable
Create a variable called message and set it to the string 'Thank you for attending the meeting!'.
PowerShell
Need a hint?

Use = to assign a string to a variable in PowerShell.

3
Use a ForEach loop to create personalized messages
Use a ForEach loop with the variable client to go through each name in $clients. Inside the loop, create a variable called personalMessage that combines client and message using string interpolation.
PowerShell
Need a hint?

Use foreach ($client in $clients) { ... } and inside use "$client, $message" for string interpolation.

4
Print each personalized message
Inside the ForEach loop, add a line to print the personalMessage variable using Write-Output.
PowerShell
Need a hint?

Use Write-Output $personalMessage to print the message inside the loop.