Bird
0
0

Identify the error in this advanced function declaration:

medium📝 Debug Q6 of 15
PowerShell - Functions
Identify the error in this advanced function declaration:
function Set-Value {
  [CmdletBinding(SupportsShouldProcess=$true)]
  param(
    [int]$Value
  )
  if ($PSCmdlet.ShouldProcess("Value")) {
    Write-Output "Value set to $Value"
  }
}
AMissing mandatory parameter attribute
BIncorrect use of $PSCmdlet.ShouldProcess method
CCmdletBinding attribute syntax is invalid
DShouldProcess requires a target and action description
Step-by-Step Solution
Solution:
  1. Step 1: Review ShouldProcess usage

    The ShouldProcess method requires a target and an action description.
  2. Step 2: Check current call

    The code calls ShouldProcess with only one string "Value".
  3. Step 3: Identify error

    ShouldProcess requires a target and action description.
  4. Final Answer:

    ShouldProcess requires a target and action description -> Option D
  5. Quick Check:

    ShouldProcess needs target and action for confirmations [OK]
Quick Trick: Use ShouldProcess with target and action description [OK]
Common Mistakes:
  • Omitting action description in ShouldProcess
  • Misusing $PSCmdlet.ShouldProcess as a property
  • Confusing CmdletBinding syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes