0
0
PowerShellscripting~5 mins

Return values in PowerShell - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a return value in PowerShell?
A return value is the output a function sends back after it finishes running. It can be used later in the script.
Click to reveal answer
beginner
How do you return a value from a PowerShell function?
You use the return keyword followed by the value you want to send back.
Click to reveal answer
intermediate
What happens if you don't use return in a PowerShell function?
PowerShell returns any output generated by the function automatically, even without the return keyword.
Click to reveal answer
intermediate
Can a PowerShell function return multiple values?
Yes, a function can output multiple values by writing them to the output stream. These values can be collected as an array.
Click to reveal answer
advanced
What is the difference between return and outputting values directly in PowerShell?
return exits the function immediately and sends back the value. Outputting values without return sends them but the function continues running.
Click to reveal answer
What keyword is used to explicitly send a value back from a PowerShell function?
Areturn
Bsend
Coutput
Dexit
If a PowerShell function outputs a value but does not use return, what happens?
AThe value is ignored
BThe script stops running
CThe value is returned automatically
DThe function throws an error
How can a PowerShell function return multiple values?
ABy calling another function
BBy using multiple <code>return</code> statements
CBy separating values with commas in <code>return</code>
DBy outputting values one after another
What does the return keyword do besides sending a value back?
APauses the function
BExits the function immediately
CStarts a new function
DPrints a message
Which of these is a correct way to return the number 5 from a PowerShell function?
Areturn 5
Bsend 5
Coutput 5
Dexit 5
Explain how return values work in PowerShell functions and how they can be used.
Think about how functions send data back to the caller.
You got /4 concepts.
    Describe the difference between using return and just outputting values in a PowerShell function.
    Consider what happens after sending the value.
    You got /3 concepts.