Skip to content

Latest commit

 

History

History
61 lines (49 loc) · 900 Bytes

UseShouldProcessForStateChangingFunctions.md

File metadata and controls

61 lines (49 loc) · 900 Bytes
description ms.custom ms.date ms.topic title
Use ShouldProcess For State Changing Functions
PSSA v1.21.0
06/28/2023
reference
UseShouldProcessForStateChangingFunctions

UseShouldProcessForStateChangingFunctions

Severity Level: Warning

Description

Functions whose verbs change system state should support ShouldProcess.

Verbs that should support ShouldProcess:

  • New
  • Set
  • Remove
  • Start
  • Stop
  • Restart
  • Reset
  • Update

How

Include the SupportsShouldProcess argument in the CmdletBinding attribute.

Example

Wrong

function Set-ServiceObject
{
    [CmdletBinding()]
    param
    (
        [string]
        $Parameter1
    )
    ...
}

Correct

function Set-ServiceObject
{
    [CmdletBinding(SupportsShouldProcess = $true)]
    param
    (
        [string]
        $Parameter1
    )
    ...
}