📖 Scenario: You are creating a simple script to combine parts of a person's name into a full name. This is like putting together pieces of a puzzle to see the whole picture.
🎯 Goal: Build a PowerShell script that creates a full name by joining first name, middle name, and last name using string concatenation.
📋 What You'll Learn
Create variables for first name, middle name, and last name with exact values.
Create a variable for a space character to use as a separator.
Concatenate the names with spaces in between using the + operator.
Print the full name to the console.
💡 Why This Matters
🌍 Real World
Combining strings is common when creating messages, file paths, or user information in scripts.
💼 Career
Knowing how to join strings helps automate report generation, logging, and user interface text in many IT and scripting jobs.
Progress0 / 4 steps
1
Create name parts
Create three variables called $firstName, $middleName, and $lastName with the exact values "John", "F.", and "Kennedy" respectively.
PowerShell
Hint
Use the = sign to assign the exact strings to each variable.
2
Create space separator
Create a variable called $space and assign it the exact value of a single space character " ".
PowerShell
Hint
Remember a space is just a string with one space character inside quotes.
3
Concatenate full name
Create a variable called $fullName that concatenates $firstName, $space, $middleName, $space, and $lastName using the + operator.
PowerShell
Hint
Use the plus sign + to join strings together in PowerShell.
4
Print the full name
Write a line to print the variable $fullName to the console using Write-Output.
PowerShell
Hint
Use Write-Output $fullName to show the full name on the screen.
Practice
(1/5)
1. Which operator is used in PowerShell to join two strings together?
easy
A. /
B. -
C. +
D. *
Solution
Step 1: Understand string joining in PowerShell
PowerShell uses the plus sign (+) to concatenate or join strings.
Step 2: Identify the correct operator
Among the options, only + is used for string concatenation.
Final Answer:
+ -> Option C
Quick Check:
String concatenation operator = + [OK]
Hint: Use + to join strings simply in PowerShell [OK]
Common Mistakes:
Using - instead of +
Trying to use * for strings
Using / which is division
2. Which of the following is the correct syntax to concatenate variables $a and $b with a space between them in PowerShell?
easy
A. $a + ' ' + $b
B. $a - ' ' - $b
C. $a * ' ' * $b
D. $a / ' ' / $b
Solution
Step 1: Check operator for concatenation
PowerShell uses + to join strings, so + is correct here.
Step 2: Confirm space inclusion
Adding ' ' between variables adds a space between the joined strings.
Final Answer:
$a + ' ' + $b -> Option A
Quick Check:
Concatenate with + and add space as ' ' [OK]
Hint: Add spaces manually with ' ' when joining strings [OK]
Common Mistakes:
Using - instead of +
Forgetting to add space
Using * or / operators
3. What will be the output of this PowerShell code?
$first + $second joins "Good" and "Morning" without space, resulting in "GoodMorning".
Step 2: Identify missing space
To separate words, a space string ' ' should be added between variables.
Final Answer:
Missing space between words in concatenation -> Option B
Quick Check:
Concatenation lacks space, so words join directly [OK]
Hint: Add ' ' between strings to include spaces [OK]
Common Mistakes:
Assuming + adds space automatically
Thinking variables are undeclared
Believing Write-Output is wrong
5. You want to create a full name string from variables $firstName and $lastName with a space in between. Which of these PowerShell commands correctly does this and outputs the full name?
hard
A. Write-Output $firstName * ' ' * $lastName
B. Write-Output $firstName + $lastName
C. Write-Output $firstName - $lastName
D. Write-Output "$firstName $lastName"
Solution
Step 1: Understand string interpolation in double quotes
Using double quotes with variables inside inserts their values with spaces as typed.
Step 2: Compare options
Write-Output "$firstName $lastName" uses double quotes with space between variables, producing correct full name with space.
Final Answer:
Write-Output "$firstName $lastName" -> Option D
Quick Check:
Double quotes allow variable insertion with spaces easily [OK]
Hint: Use double quotes to insert variables with spaces easily [OK]
Common Mistakes:
Forgetting space in concatenation
Using - or * operators incorrectly
Not using double quotes for interpolation
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.