Skip to content

Latest commit

 

History

History
55 lines (43 loc) · 974 Bytes

UseShouldProcessForStateChangingFunctions.md

File metadata and controls

55 lines (43 loc) · 974 Bytes

Pattern: Missing ShouldProcess for state changing function

Issue: -

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 of incorrect code:

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

Example of correct code:

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

Further Reading