Expand Minimize

SPC019105: Functions that use ShouldProcess sould support Force to bypass

In order to correctly support the force boolean switch, you need to call ShouldContinue correctly when you call ShouldProcess.

CheckId SPC019105
TypeName CallShouldContinueWhenShouldProcessTrue
Severity CriticalWarning
Type PoShFile

Bad Practice

Begin
{
  $pscmdlet.ShouldContinue("Yes", "No")
}
Process
{
  if($pscmdlet.ShouldProcess("foo","bar"))
  {
  }
}
End
{
}
Good Practice
Begin
{
}
Process
{
  if($pscmdlet.ShouldProcess("foo","bar"))
  {
  }
}
End
{
  if($pscmdlet.ShouldContinue("Yes", "No")
  {
  }
}

Disclaimer: The views and opinions expressed in this documentation and in SPCAF do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. SPCAF and RENCORE are registered trademarks of Rencore. All other trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners.