Last active
October 18, 2017 03:48
-
-
Save techthoughts2/ee120ae57b0b97b1a62828065b67e4da to your computer and use it in GitHub Desktop.
Test for a file and remove the file if found.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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