How to delete files and folders using PowerShell

Shaant Minhas

powershell

Looking for more How To posts? Check out our How To Page for all the latest tips on Windows, Microsoft Teams, LinkedIn, and more!

Deleting all your files and folders manually can be a hassle. But, if you know your way around the PowerShell, it doesn’t have to be. In this article, we present different ways to delete your Windows files and folders using the PowerShell.

Deleting your files and folders with PowerShell

PowerShell is a free command automation tool provided by Windows. In a nutshell, it helps you gain more control over the operating system through the helps of a Shell, which start inside in a Command prompt window.

It makes use of Cmdlets, also called command-let, which are the in-built commands in the PowerShell that help you execute specific tasks.

So, when you’re looking to delete your files and folders, these are the exact Cmdlets that we’re going to be using. Let’s look at how to delete your files first.

How to delete your files and folder with PowerShell

The most simple and clear-but method to delete your files and folders using PowerShell is through the Remove-Item cmdlet. Simply type in the cmdlet in the PowerShell along with the parameters, and your file or folders will be removed. Here’s how:

  1. Go to the Start menu search bar, type in ‘powershell,’ and select the best match.
  2. In the Command prompt, type in the following cmdlet and hit Enter:
    Remove-Item

      [-Path] <String[]>

      [-Filter <String>]

      [-Include <String[]>]

      [-Exclude <String[]>]

      [-Recurse]

      [-Force]

      [-Credential <PSCredential>]

      [-WhatIf]

      [-Confirm]

      [-Stream <String[]>]

      [<CommonParameters>]

In the above command, the Remove-Item is the cmdlet which imitates the process for deletion, while the rest of characters in brackets are optional parameters you might have to use. Here’s a brief explanation of all the parameters:

Path: The Path parameter is necessary to specify the location of your file or folder.

Filter: Helpful in providing a filter for the Path parameters.

Include: This helps you include files and folders that meet your specific needs.

Exclude: You can remove files and folders from your list through this.

Recurse: Specifies that the cmdlet deletes files in the specific locations.

Force: Forces the cmdlet to delete files or folders that can’t be changed easily, such as the hidden or read-only files or read-only aliases or variables.

WhatIf: Shows you a trial run of the Command.

Confirm: Asks you for confirmation before run the Cmdlet.

Stream: Useful for deleting alternative data streams.

For instance, we can show you how the deletion would work with specific parameters. Here’s how:

Remove-item C:\Users\user-name\Desktop\articles\newBook.txt

windows powershell

The above command deletes a .txt file called ‘newBook’ located at the desktop. Here, we’ve used a few of the parameters described in the command above. You can replace the file or folder just like in the command above, and you’ll be able to delete the files you’d want to.

Moreover, if you’re looking to remove hidden files or folders, then simply add in the -Force parameter, and you’ll be good to go. Here’s how:

Remove-Item C:\Program Files\VLC -Force

Deleting multiple files in a single go

So, that’s how you can delete your files with the PowerShell. But that’s not all. With the help of PowerShell cmdlets, you can also remove multiple files at once. Here’s how:

Remove-item file-path1, file-path2, file-path3

Type in the above command in your PowerShell and the specified files will be deleted. Here, you simply have to enter the specific file paths in place of file-path1, file-path2 and file-path3, and you’ll be good to go. You can apply the same method for the getting rid of multiple folders, and by the end of it, you’ll be done.

Deleting your files and folders using PowerShell

Removing your Windows files and folders doesn’t have to be difficult. As we saw above, you can remove your files and folders with Windows PowerShell without any troubles. But, as we’d mentioned right at the beginning, your Windows PowerShell is a powerhouse of tools and accessibility waiting to be discovered and used. So, don’t stop here, and keep learning more about the PowerShell.