Home

Powershell: Delete File if Exists

Posted by SteveHardie | On: Sep 25 2012

Powershell script to delete a file if it already exists:

If (Test-Path $strFileName){
	Remove-Item $strFileName
}

See Also:
Powershell: Check If File Exists
Powershell: Delete Folder if Exists
Test-Path
Remove-Item

5 Comments

  1. Tobias says:

    Thanks. Your site gave me a perfect Google hit

  2. ola says:

    works like a charm

Leave a comment