Bird
Raised Fist0
PowerShellscripting~10 mins

First PowerShell command - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to display the text "Hello, World!" in PowerShell.

PowerShell
Write-[1] "Hello, World!"
Drag options to blanks, or click blank then click option'
AHost
BOutput
COutputLine
DHostLine
Attempts:
3 left
💡 Hint
Common Mistakes
Using Write-Output instead of Write-Host for direct console display.
Misspelling the command name.
Using commands that do not exist in PowerShell.
2fill in blank
medium

Complete the code to store the number 5 in a variable named $num.

PowerShell
$num = [1]
Drag options to blanks, or click blank then click option'
A"5"
B5
C$5
Dfive
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the number inside quotes, which makes it a string.
Using invalid variable names like $5.
Writing the number as a word instead of a digit.
3fill in blank
hard

Fix the error in the code to correctly display the value of $name variable.

PowerShell
Write-Host [1]
Drag options to blanks, or click blank then click option'
A"name"
Bname
C$name
D'$name'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the $ sign before the variable name.
Putting the variable name inside quotes which prints the literal text.
Using single quotes which do not expand variables.
4fill in blank
hard

Fill both blanks to create a loop that prints numbers 1 to 3.

PowerShell
for ($i = 1; $i [1] 3; $i[2]) { Write-Host $i }
Drag options to blanks, or click blank then click option'
A-le
B++
C-lt
D--
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-lt' instead of '-le' causing the loop to stop early.
Using '--' which decreases the counter instead of increasing.
Using incorrect operators causing syntax errors.
5fill in blank
hard

Fill all three blanks to create a hashtable with keys 'Name' and 'Age' and print the 'Name'.

PowerShell
$person = @{ [1] = 'John'; [2] = 30 }`nWrite-Host $person.[3]
Drag options to blanks, or click blank then click option'
AName
BAge
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around keys in the hashtable.
Accessing the hashtable with wrong key names.
Mixing up keys when printing the value.

Practice

(1/5)
1. What does the PowerShell command Write-Output "Hello, World!" do?
easy
A. It opens a new PowerShell window.
B. It saves the text to a file automatically.
C. It displays the text "Hello, World!" on the screen.
D. It deletes the text from the screen.

Solution

  1. Step 1: Understand Write-Output command

    The Write-Output command sends the specified text or data to the screen or pipeline.
  2. Step 2: Analyze the given command

    The command Write-Output "Hello, World!" prints the text "Hello, World!" on the screen.
  3. Final Answer:

    It displays the text "Hello, World!" on the screen. -> Option C
  4. Quick Check:

    Write-Output prints text = D [OK]
Hint: Write-Output prints text to screen or pipeline [OK]
Common Mistakes:
  • Thinking it saves text to a file automatically
  • Confusing output with deleting or opening windows
  • Assuming it runs scripts instead of showing text
2. Which of the following is the correct syntax to display the number 123 in PowerShell?
easy
A. Write-Output "123"
B. Write-Output 123
C. Write-Output (123)
D. Write-Output [123]

Solution

  1. Step 1: Check syntax for Write-Output with numbers

    Write-Output can print numbers directly without quotes or brackets.
  2. Step 2: Evaluate each option

    Write-Output 123 uses Write-Output 123 which is correct syntax to print number 123.
  3. Final Answer:

    Write-Output 123 -> Option B
  4. Quick Check:

    Number without quotes prints correctly = B [OK]
Hint: Numbers print without quotes in Write-Output [OK]
Common Mistakes:
  • Putting numbers inside brackets or square brackets
  • Using quotes unnecessarily for numbers
  • Confusing parentheses as required syntax
3. What will be the output of this PowerShell command?
Write-Output (5 + 3)
medium
A. 8
B. 5 + 3
C. (5 + 3)
D. Write-Output (5 + 3)

Solution

  1. Step 1: Understand expression evaluation in Write-Output

    Parentheses cause the expression inside to be evaluated before output.
  2. Step 2: Calculate the expression (5 + 3)

    5 + 3 equals 8, so Write-Output prints 8.
  3. Final Answer:

    8 -> Option A
  4. Quick Check:

    Write-Output evaluates expressions = A [OK]
Hint: Parentheses evaluate expressions before printing [OK]
Common Mistakes:
  • Thinking it prints the expression as text
  • Confusing output with command text
  • Ignoring parentheses effect on evaluation
4. Identify the error in this PowerShell command:
Write-Output Hello World
medium
A. Missing quotes around text with spaces
B. Write-Output cannot print text
C. Command should be lowercase
D. No error, command is correct

Solution

  1. Step 1: Check syntax for strings with spaces

    Text with spaces must be enclosed in quotes to be treated as one string.
  2. Step 2: Analyze given command

    Write-Output Hello World treats Hello and World as separate arguments causing error or unexpected output.
  3. Final Answer:

    Missing quotes around text with spaces -> Option A
  4. Quick Check:

    Text with spaces needs quotes = C [OK]
Hint: Put quotes around multi-word text in Write-Output [OK]
Common Mistakes:
  • Assuming Write-Output can't print text
  • Ignoring quotes for multi-word strings
  • Thinking command case matters in PowerShell
5. You want to print the result of adding two numbers, 7 and 4, using a single PowerShell command. Which command should you use?
hard
A. Write-Output 7, 4
B. Write-Output "7 + 4"
C. Write-Output 7 4
D. Write-Output (7 + 4)

Solution

  1. Step 1: Understand how to calculate expressions in Write-Output

    Using parentheses causes PowerShell to evaluate the expression before printing.
  2. Step 2: Evaluate each option

    Write-Output (7 + 4) uses Write-Output (7 + 4), which calculates 11 and prints it.
  3. Final Answer:

    Write-Output (7 + 4) -> Option D
  4. Quick Check:

    Parentheses evaluate math before output = A [OK]
Hint: Use parentheses to calculate before printing [OK]
Common Mistakes:
  • Putting math inside quotes prints text, not result
  • Writing multiple arguments without parentheses
  • Using commas prints array, not sum
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard