public/Erase-Folder.ps1
function Erase-Folder { [cmdletbinding(SupportsShouldProcess=$True)] param ( [Parameter(Position=0,mandatory=$true)] [string] $TargetDirectory ) $EmptyDir = "$env:TEMP\empty_temp" # create a empty temp folder for robocopy later if (!(Test-Path $EmptyDir)) { New-Item -Path $EmptyDir -ItemType Directory } # warn Write-Warning "You are about to erase everything in $TargetDirectory are you sure you want to continue" -WarningAction Inquire # use robocopy to mirror the empty directory over the top of the target directory robocopy $EmptyDir $TargetDirectory /MIR # remove empty temp folder and target folder Remove-Item $EmptyDir,$TargetDirectory -Force -Recurse } |