# encoding: ascii
# api: powershell
# title: Demo-ShouldProcess
# description: Shows how to use SupportsShouldProcess and Confirm
# version: 0.1
# author: Joel Bennett
# license: CC0
# x-poshcode-id: 3291
# x-archived: 2016-06-10T15:25:52
# x-published: 2012-03-15T15:50:00
#
#
[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact="Medium")]
param([Switch]$Force)

$RejectAll = $false;
$ConfirmAll = $false;

foreach($file in ls) {
   if($PSCmdlet.ShouldProcess( "Removed the file '$($file.Name)'",
                               "Remove the file '$($file.Name)'?",
                               "Removing Files" )) {
      if($Force -Or $PSCmdlet.ShouldContinue("Are you REALLY sure you want to remove '$($file.Name)'?", "Removing '$($file.Name)'", [ref]$ConfirmAll, [ref]$RejectAll)) {
         "Removing $File"
      }
   }
}
