Consider the test script shown below:
function New-Folder {
[cmdletbinding(SupportsShouldProcess,
ConfirmImpact = 'High')]
param(
[parameter(ValueFromPipeline)]
[string[]] $Item,
[switch] $Force
)
process {
foreach ($i in $Item) {
if ($PSCmdlet.ShouldProcess($i)) {
Write-Verbose "Creating $i"
New-Item -Name $i -ItemType Directory -Confirm:$false -Force:$Force | Out-Null
}
}
}
}
When the ConfirmImpact is set to ‘High’ I can’t figure out a way to properly implement the Force parameter to bypass all confirm prompts when the Force switch is used. I’ve read it’s bad practice to implement $Force as part of the ShouldProcess conditional statement so where should I implement $Force?
Any help is appreciated.