Powershell - Delete Folder



Cmdlet

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

Example 1

In this example, we'll delete a folder D:\Temp\Test Folder1

Type the following command in PowerShell ISE Console

Remove-Item 'D:\temp\Test Folder1'

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 Folder1 recursively. 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 folders are now removed.

powershell_files_folders.htm
Advertisements