description | ms.custom | ms.date | ms.topic | title |
---|---|---|---|---|
Use SupportsShouldProcess |
PSSA v1.21.0 |
06/28/2023 |
reference |
UseSupportsShouldProcess |
Severity Level: Warning
This rule discourages manual declaration of WhatIf
and Confirm
parameters in a function/cmdlet.
These parameters are, however, provided automatically when a function declares a CmdletBinding
attribute with SupportsShouldProcess
as its named argument. Using SupportsShouldProcess
not only
provides these parameters but also some generic functionality that allows the function/cmdlet
authors to provide the desired interactive experience while using the cmdlet.
function foo {
param(
$param1,
$Confirm,
$WhatIf
)
}
function foo {
[CmdletBinding(SupportsShouldProcess)]
param(
$param1
)
}