Powershell - Delete File



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
Advertisements