Skip to content

Instantly share code, notes, and snippets.

@techthoughts2
Last active October 18, 2017 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techthoughts2/ee120ae57b0b97b1a62828065b67e4da to your computer and use it in GitHub Desktop.
Save techthoughts2/ee120ae57b0b97b1a62828065b67e4da to your computer and use it in GitHub Desktop.
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."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment