Skip to content

Latest commit

 

History

History
53 lines (42 loc) · 694 Bytes

UseShouldProcessForStateChangingFunctions.md

File metadata and controls

53 lines (42 loc) · 694 Bytes

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 attribute SupportsShouldProcess, in the CmdletBindingBinding.

Example

Wrong

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

Correct

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