Powershell - Delete File


Advertisements

Cmdlet

Remove-Item cmdlet is used to delete a file by passing the path of the file to be deleted.

Example 1

In this example, we'll delete a file D:\Temp\Test Folder\Test.txt

Type the following command in PowerShell ISE Console

Remove-Item 'D:\temp\Test Folder\test.txt'

You can see the Test Folder1 in Windows Explorer is deleted now.

Example 2

In this example, we'll remove the folder D:\Temp\Test Folder recursively deleting its all files. In first example, PowerShell confirms if directory is not empty. In this case, it will simply delete the item.

Type the following command in PowerShell ISE Console

Remove-Item 'D:\temp\Test Folder' -Recurse

You can see the content of temp folder in Windows Explorer where its folder is now removed.

powershell_files_folders.htm

Useful Video Courses


Video

Powershell for beginners

15 Lectures 3.5 hours

Fabrice Chrzanowski

Video

Learning Task Automation using Windows PowerShell

35 Lectures 2.5 hours

Vijay Saini

Video

The Complete PowerShell 7 course: Beginner To Advanced

145 Lectures 12.5 hours

Fettah Ben

Advertisements