Bird
0
0

Identify the error in this PowerShell function:

medium📝 Debug Q14 of 15
PowerShell - Functions
Identify the error in this PowerShell function:
function ShowMessage {
  Write-Output "Message: $message"
}
ShowMessage "Hello"
AFunction is missing a parameter to receive the message
BWrite-Output cannot print variables
CFunction name cannot have uppercase letters
DMissing semicolon after Write-Output
Step-by-Step Solution
Solution:
  1. Step 1: Check how the function uses variables

    The function tries to use $message but does not define or receive it as a parameter.
  2. Step 2: Understand function parameter passing

    Without a parameter or variable assignment, $message is undefined, causing no output or error.
  3. Final Answer:

    Function is missing a parameter to receive the message -> Option A
  4. Quick Check:

    Undefined variable in function = Function is missing a parameter to receive the message [OK]
Quick Trick: Functions need parameters to accept input values [OK]
Common Mistakes:
  • Thinking Write-Output can't print variables
  • Believing function names must be lowercase
  • Adding unnecessary semicolons

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes