Bird
0
0

What will this PowerShell function output?

medium📝 Command Output Q5 of 15
PowerShell - Functions
What will this PowerShell function output?
function ShowMessage { param([string]$msg = 'Hello') Write-Output $msg }
ShowMessage
AHello
Bmsg
CError: missing argument
Dnull
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter default

    Parameter msg defaults to 'Hello'.
  2. Step 2: Function call without argument

    Calling ShowMessage without argument uses default 'Hello'.
  3. Final Answer:

    Hello -> Option A
  4. Quick Check:

    No argument means default used = 'Hello' [OK]
Quick Trick: No argument? Default string prints [OK]
Common Mistakes:
  • Expecting error for missing argument
  • Printing parameter name instead of value
  • Assuming null output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes