0
0
PowerShellscripting~15 mins

-replace operator in PowerShell - Mini Project: Build & Apply

Choose your learning style9 modes available
Using the -replace Operator in PowerShell
📖 Scenario: You work in a small office where you keep a list of employee email addresses. Some emails have an old domain that needs to be updated to a new domain.
🎯 Goal: You will create a list of email addresses, set the old domain to replace, use the -replace operator to update the emails, and then display the updated list.
📋 What You'll Learn
Create a list of email addresses with exact values
Create a variable for the old domain string
Use the -replace operator to update the domain in all emails
Print the updated list of email addresses
💡 Why This Matters
🌍 Real World
Updating email domains is common when companies rebrand or merge. Automating this saves time and avoids mistakes.
💼 Career
Knowing how to use the <code>-replace</code> operator helps in scripting tasks for system administration and data cleanup.
Progress0 / 4 steps
1
Create the list of email addresses
Create a list called emails with these exact email addresses: "alice@oldcompany.com", "bob@oldcompany.com", and "carol@oldcompany.com".
PowerShell
Need a hint?

Use @() to create an array in PowerShell.

2
Set the old domain to replace
Create a variable called oldDomain and set it to the string "oldcompany.com".
PowerShell
Need a hint?

Use = to assign the string to the variable.

3
Replace the old domain with the new domain
Create a new list called updatedEmails by replacing oldDomain with "newcompany.com" in each email using the -replace operator.
PowerShell
Need a hint?

Use -replace with the syntax: $list -replace old, new.

4
Display the updated email addresses
Print the updatedEmails list to show the new email addresses.
PowerShell
Need a hint?

Simply output the variable updatedEmails to display the list.