How To Delete Folders Using PowerShell

By Ammarrauf01

How To Delete Folders Using PowerShell. In this article, we will summarize the methods to make PowerShell Delete Folders. PowerShell is a built-in framework application in Windows. It assists to perform different administrative tasks.

Deleting a simple folder is a very easy task. But, when you have to delete a large folder using Windows File Explorer, it may take a lot of time. However, you can make this task very easy by using Command lines in PowerShell.

How To Delete Folders Using PowerShell?

Method 1 – Delete Specific Folder Using ‘Remove- Item’ Commands:

To delete the specific files or folder, follow the steps below:

1.Type PowerShell in the Windows search bar.
2.Right-click on it and select Run as an administrator.

How To Delete Folders Using PowerShell - pic1

3.Type the following line of commands in PowerShell, to check the contents of the specified folder (e.g. test):

Get-ChildItem D:\test\

4.Check the files and the folders inside the folder.

How To Delete Folders Using PowerShell - pic2

5.Then, to remove the specific file or folder, type the following command: [Here we are deleting the test2 folder and all the files inside it]

Remove-Item D:\test\test1\test2\ -Verbose

How To Delete Folders Using PowerShell - pic3

6.Enter Y from the keyboard to confirm the action.

How To Delete Folders Using PowerShell - pic4

Method 2 – Delete The Contents Using ‘del’ Command:

You can delete all files in the folder by following the steps below:

1.Type PowerShell in the Windows search bar.
2.Right-click on it and select Run as an administrator.

How To Delete Folders Using PowerShell - pic5

3.In the PowerShell window, type the following command and press Enter: [Change the folder and drive names accordingly.

del D:\test\

How To Delete Folders Using PowerShell - pic6

4.Enter Y from the keyboard to delete the entire directory.

How To Delete Folders Using PowerShell - pic7

Method 3 – Delete Folder Using The ‘rmdir’ Command:

You can delete or remove specific directories, by using the rmdir command in the PowerShell. To do so, follow the steps below:

1.Run the PowerShell as an administrator.

How To Delete Folders Using PowerShell - pic8

2.Type the following command and press the enter button to execute the commands. [Change folder and drive name accordingly]

rmdir D:\test\

How To Delete Folders Using PowerShell - pic9

3.Enter Y from the keyboard to delete the entire directory.

*del :- Delete all the files in a folder and makes the folder empty
*remove-Item :- Delete any files with any kind of extensions.
*rmdir :- Delete or remove a specific directory.

How To Delete Folders Using PowerShell - pic10