In this article, we take a look at how to delete a file using, PowerShell.
Example 1: One Liner: Delete a File
Windows:
Remove-Item -Path "D:/Data/file1.txt" -Force
macOS:
Remove-Item -Path "/Users/c2ctechtv/Desktop/file1.txt"
Example 2: Using PowerShell Script
$filePath = Read-Host "Enter the file path to delete!"
if (Test-Path -Path $filePath) {
Remove-Item -Path $filePath -Force
Write-Host "The file was deleted successfully!"
} else {
Write-Host "File not deleted! Make sure the file exists or the file path is correct!."
}

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!