Public/Remove-ItemIfExists.ps1
function Remove-ItemIfExists { <# .Synopsis Remove-ItemIfExists does this... Short description .DESCRIPTION Remove-ItemIfExists does this, that, and the other... Long description .EXAMPLE Remove-ItemIfExists "DEV" .\Here\this\path\file.txt #> [CmdletBinding(SupportsShouldProcess=$true)] param ( [Parameter( Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [string]$Path ) BEGIN{ Write-Verbose "Starting Remove-ItemIfExists..." }#begin PROCESS{ if ($psCmdlet.ShouldProcess(<# on target --> #>"$Path", <# What if: Performing operation --> #>"Remove recurse force if exists")) { if (Test-Path $Path -PathType Any) { Remove-Item $Path -Recurse -Force } } }#process END{ Write-Verbose "Finished Remove-ItemIfExists..." }#end } |