0
0
PowerShellscripting~15 mins

Here-strings for multiline in PowerShell - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Here-strings for Multiline Text in PowerShell
📖 Scenario: You are creating a script to store a multiline message that will be displayed later. This message includes multiple lines of text, like a short poem or a note.
🎯 Goal: Learn how to use PowerShell here-strings to store and display multiline text easily.
📋 What You'll Learn
Create a variable with a multiline string using a here-string.
Use the correct syntax for starting and ending a here-string.
Print the multiline string exactly as it is stored.
💡 Why This Matters
🌍 Real World
Here-strings are useful when you need to store or output blocks of text like emails, reports, or configuration files in scripts.
💼 Career
Many automation and scripting jobs require handling multiline text data cleanly, making here-strings an essential skill for PowerShell users.
Progress0 / 4 steps
1
Create a multiline string variable using a here-string
Create a variable called message and assign it a multiline string using a here-string. The string should contain exactly these three lines:
Hello,
This is a multiline
message.
PowerShell
Need a hint?

Use @" to start and "@ to end the here-string. Write the lines exactly as given between them.

2
Add a configuration variable for a greeting prefix
Create a variable called greeting and set it to the string "Note:".
PowerShell
Need a hint?

Just assign the string "Note:" to the variable greeting.

3
Combine the greeting and message using a here-string
Create a new variable called fullMessage that combines the greeting and the message variables into one multiline string using a here-string. The first line should be the greeting, followed by the original message lines.
PowerShell
Need a hint?

Start a new here-string for fullMessage. Inside it, place $greeting on the first line, then $message on the next lines.

4
Print the combined multiline message
Use Write-Output to print the fullMessage variable so the multiline text appears exactly as stored.
PowerShell
Need a hint?

Use Write-Output $fullMessage to display the multiline string.