Recall & Review
beginner
What is a function in PowerShell?
A function is a named block of code that performs a specific task and can be reused multiple times in a script.
Click to reveal answer
beginner
How do you define a simple function named
SayHello in PowerShell?Use the syntax:<br>
function SayHello {
Write-Output "Hello!"
}Click to reveal answer
beginner
What keyword starts a function definition in PowerShell?
The keyword
function is used to start defining a function.Click to reveal answer
beginner
How can you call or run a function named
SayHello after defining it?Simply type the function name:<br>
SayHelloThis runs the code inside the function.
Click to reveal answer
beginner
Why use functions in scripts?
Functions help organize code, avoid repetition, and make scripts easier to read and maintain.
Click to reveal answer
Which keyword is used to define a function in PowerShell?
✗ Incorrect
In PowerShell, the keyword to define a function is 'function'.
How do you call a function named
GetDate in PowerShell?✗ Incorrect
You call a function by typing its name alone, like 'GetDate'. Parentheses are optional and usually omitted.
What does the following function do?<br>
function Greet { Write-Output "Hi!" }✗ Incorrect
The function named Greet outputs the text 'Hi!' when you run it.
Why should you use functions in your scripts?
✗ Incorrect
Functions help organize code and let you reuse it without rewriting.
Which of these is a correct function definition in PowerShell?
✗ Incorrect
Only option A uses correct PowerShell syntax for defining a function.
Explain how to define and call a simple function in PowerShell.
Think about the keywords and how you run the function after defining it.
You got /4 concepts.
Describe why functions are useful in scripting with PowerShell.
Consider how functions help when scripts get bigger.
You got /4 concepts.