Recall & Review
beginner
What is a default parameter value in PowerShell functions?
A default parameter value is a value assigned to a function parameter that is used if no argument is provided when the function is called. It helps avoid errors and makes parameters optional.
Click to reveal answer
beginner
How do you define a default value for a parameter in a PowerShell function?
You assign the default value directly in the parameter declaration using the equals sign, like: param([string]$name = "Guest").
Click to reveal answer
beginner
Why are default parameter values useful in scripting?
They make functions easier to use by allowing callers to skip parameters when the default is fine. This reduces the need to always specify every argument.
Click to reveal answer
beginner
What happens if you call a PowerShell function without providing a value for a parameter that has a default?
The function uses the default value assigned to that parameter automatically.
Click to reveal answer
beginner
Show a simple PowerShell function with a default parameter value and explain its output when called with and without an argument.
Example:
function Greet {
param([string]$name = "Friend")
"Hello, $name!"
}
Calling Greet returns "Hello, Friend!" because no argument was given.
Calling Greet -name "Anna" returns "Hello, Anna!" because the argument overrides the default.
Click to reveal answer
How do you assign a default value to a parameter in a PowerShell function?
✗ Incorrect
In PowerShell, default values are assigned using the equals sign (=) inside the param block.
What happens if you call a function without specifying a parameter that has a default value?
✗ Incorrect
If a parameter has a default value, PowerShell uses it when no argument is provided.
Why use default parameter values in scripts?
✗ Incorrect
Default values let users call functions without specifying every parameter.
Which of these is a correct default parameter declaration in PowerShell?
✗ Incorrect
Only the equals sign (=) is valid for default values in PowerShell parameters.
If a function parameter has a default value, can you still provide a different value when calling the function?
✗ Incorrect
Providing an argument overrides the default value.
Explain how to use default parameter values in a PowerShell function and why they are helpful.
Think about how to make parameters optional with a fallback value.
You got /3 concepts.
Write a simple PowerShell function with a default parameter and describe what happens when you call it with and without that parameter.
Use param block and assign a default value.
You got /3 concepts.