Recall & Review
beginner
What does the
[CmdletBinding()] attribute do in a PowerShell function?It turns a regular function into an advanced function, enabling cmdlet features like parameter validation, support for common parameters, and better error handling.Click to reveal answer
beginner
How do you declare a parameter as mandatory in an advanced function?
Use the
[Parameter(Mandatory=$true)] attribute before the parameter declaration inside the param() block.Click to reveal answer
intermediate
What is the benefit of using
SupportsShouldProcess=$true in [CmdletBinding()]?It enables the function to support
-WhatIf and -Confirm parameters, allowing users to simulate or confirm actions before they run.Click to reveal answer
intermediate
Explain how
Write-Verbose works in an advanced function with [CmdletBinding()].When
[CmdletBinding()] is used, Write-Verbose outputs messages only if the user runs the function with the -Verbose switch, helping with debugging or detailed info.Click to reveal answer
beginner
What happens if you omit
[CmdletBinding()] in a PowerShell function?The function behaves like a simple script function without cmdlet features such as parameter validation, common parameters, or advanced error handling.Click to reveal answer
What attribute do you add to a PowerShell function to make it an advanced function?
✗ Incorrect
The [CmdletBinding()] attribute converts a function into an advanced function with cmdlet features.
Which parameter attribute makes a parameter required in an advanced function?
✗ Incorrect
Using [Parameter(Mandatory=$true)] makes the parameter required.
What does setting SupportsShouldProcess=$true enable?
✗ Incorrect
SupportsShouldProcess=$true enables -WhatIf and -Confirm support.
How do you show detailed messages only when requested by the user?
✗ Incorrect
Write-Verbose outputs messages only if the user adds the -Verbose switch.
What is missing if a function does NOT have [CmdletBinding()]?
✗ Incorrect
Without [CmdletBinding()], the function lacks advanced cmdlet features.
Describe how to create an advanced function in PowerShell and explain the benefits of using [CmdletBinding()]
Think about what makes a function behave like a cmdlet.
You got /4 concepts.
Explain how SupportsShouldProcess=$true affects the behavior of an advanced function and why it is useful.
Consider how users can avoid accidental changes.
You got /3 concepts.