← Docs home

Support Confirmation Requests

📐 Rule.

A cmdlet that modifies the system should call ShouldProcess to request confirmation. In special cases it also calls ShouldContinue. Call ShouldContinue only after ShouldProcess.

Enabling the calls.

Set the SupportsShouldProcess keyword on the Cmdlet attribute. If the attribute claims support but the cmdlet never calls ShouldProcess, the user can modify the system unexpectedly.

ShouldProcess vs ShouldContinue.

ShouldProcess

Covers any system modification. It is controlled by a user preference and the WhatIf parameter.

ShouldContinue

An additional check for potentially dangerous modifications. It is not controlled by any user preference or by WhatIf.

Force requirement.

A cmdlet that calls ShouldContinue should expose a Force parameter that bypasses both calls and proceeds. This lets the cmdlet run in non-interactive scripts and hosts.

Example.

Stop-Process calls ShouldContinue before stopping critical processes such as System, Winlogon, and Spoolsv.