Bird
0
0

What will be the output of this PowerShell command if you define a function named Set-UserName and call it with Set-UserName -Name 'Alice' assuming the function prints the name parameter?

medium📝 Command Output Q13 of 15
PowerShell - Cmdlets and Pipeline
What will be the output of this PowerShell command if you define a function named Set-UserName and call it with Set-UserName -Name 'Alice' assuming the function prints the name parameter?
function Set-UserName { param($Name) Write-Output "User name is $Name" }
AError: Unknown command
BSet-UserName -Name Alice
CUser name is Alice
DUser name is $Name
Step-by-Step Solution
Solution:
  1. Step 1: Understand the function definition

    The function takes a parameter called Name and outputs a string including that parameter.
  2. Step 2: Analyze the function call

    Calling Set-UserName with -Name 'Alice' passes 'Alice' to the $Name parameter, so the output is 'User name is Alice'.
  3. Final Answer:

    User name is Alice -> Option C
  4. Quick Check:

    Parameter passed correctly = output with name [OK]
Quick Trick: Parameters passed by name show in output [OK]
Common Mistakes:
  • Expecting the command name as output
  • Not recognizing variable substitution
  • Assuming an error without function definition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes