Test for a file and remove the file if found.
#tests for file and if found removes the file.
#---------------------------------------------------------
$path = 'C:\path\Test.txt'
#---------------------------------------------------------
if (Test-Path $path) {
Write-OutPut "$path detected, removing file before starting..."
try {
Remove-Item -Path $path -Force -Confirm:$false -ErrorAction Stop
}
catch {
Write-OutPut "Unable to remove $path"
}
Write-OutPut "$path was not found. No action taken."
}