Bird
0
0

What will be the output of this PowerShell script?

medium📝 Command Output Q13 of 15
PowerShell - Functions
What will be the output of this PowerShell script?
function Greet { Write-Output "Hi, $args[0]!" }
Greet "Alice"
AHi, $args[0]!
BError: Undefined variable
CGreet Alice
DHi, Alice!
Step-by-Step Solution
Solution:
  1. Step 1: Understand function parameter usage

    The function uses $args[0] to access the first argument passed, which is 'Alice'.
  2. Step 2: Evaluate the Write-Output command

    It outputs the string with 'Alice' replacing $args[0], so output is 'Hi, Alice!'.
  3. Final Answer:

    Hi, Alice! -> Option D
  4. Quick Check:

    Function argument substitution = Hi, Alice! [OK]
Quick Trick: $args[0] holds first argument passed to function [OK]
Common Mistakes:
  • Expecting literal $args[0] in output
  • Confusing function call with variable assignment
  • Assuming error due to missing parameter declaration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes