Recall & Review
beginner
What is a parameter in a PowerShell script?
A parameter is a way to pass information into a PowerShell script or function so it can use that information to do its work.
Click to reveal answer
beginner
How do you define a parameter in a PowerShell script?
You define parameters inside a
param() block at the start of the script or function.Click to reveal answer
intermediate
What is the purpose of specifying a parameter type in PowerShell?
Specifying a type helps PowerShell check that the input is the right kind of data, like a number or text, making scripts safer and clearer.
Click to reveal answer
intermediate
How can you make a parameter optional in PowerShell?
You can make a parameter optional by not marking it as mandatory. You can also provide a default value so the script uses that if no input is given.
Click to reveal answer
intermediate
What does the
[switch] parameter type do in PowerShell?A
[switch] parameter acts like a simple on/off flag. If you include it when running the script, it is true; if you leave it out, it is false.Click to reveal answer
Where do you place the
param() block in a PowerShell script?✗ Incorrect
The
param() block must be at the start of the script or function to define parameters properly.What happens if you run a script with a mandatory parameter but do not provide it?
✗ Incorrect
PowerShell prompts you to enter a value for mandatory parameters if you don't provide one.
How do you define a parameter with a default value in PowerShell?
✗ Incorrect
You assign a default value using the equals sign inside the param block.
What type of parameter is best for a simple on/off option?
✗ Incorrect
The [switch] type is designed for on/off flags without needing to specify true or false explicitly.
Which of these is a correct way to declare a mandatory parameter?
✗ Incorrect
The correct syntax uses the
Parameter attribute with Mandatory=$true.Explain how to create a PowerShell script that accepts a mandatory string parameter and an optional integer parameter with a default value.
Think about using [Parameter(Mandatory=$true)] and assigning a default value with =
You got /3 concepts.
Describe the difference between a [switch] parameter and a boolean parameter in PowerShell.
Consider how you use them when calling the script.
You got /3 concepts.