How to delete files and folders using PowerShell in windows 10?

Windows PowerShell is a powerful tool that is developed by Microsoft for purposes of task automation and configuration management. This is based on the .NET framework and it includes a command-line shell and a scripting language. Windows PowerShell is designed especially for system administrators. If you are a windows administrator and if you know PowerShell very well and you can simplify and automate tedious and repetitive tasks by creating scripts and combining multiple commands together. These Multiple Commands are called as cmdlets. Using PowerShell we can do many simple and complex things, this article will guide you to delete files and folders using PowerShell. Deleting files or folders is a normal operation in any operating system. In windows deleting files or folders is very easy, In PowerShell, it’s a little complex to delete. Remove-Item is the cmdlet used to delete a file bypassing the path of the file to be deleted.

About Remove-Item Cmdlet: The Remove-Item cmdlet deletes one or more items. Because it is supported by many providers, it can delete many different types of items, including files, folders, registry keys, variables, aliases, and functions.

Table of Contents

To Delete a Single File Using PowerShell

Open PowerShell from the windows start menu, or Open run command by pressing Windows + R and type PowerShell. This will open the PowerShell window. Type the following command to delete any single file

Remove-Item ‘C:\TestFolder’

delete files and folders using PowerShell

Type the file path by replacing the TestFolder Once you enter the command you will get the confirmation to delete the file, give Yes to delete a file.

To Delete a Single Folder Using PowerShell

Open PowerShell from the Windows start menu, or Open run command by pressing Windows + R and type PowerShell. This will open the PowerShell window.

Note: Make sure the folder path is correct while entering this cmdlet this won’t ask any permission it will directly delete the folder in silence. Type the following command to delete any folder recursively deleting its all files inside.

Remove-Item ‘C:\Users\Prem\Desktop\Testfolder’ –Recurse

Once you enter the command first the cmdlet will check that the directory is not empty, if it’s not empty it will simply delete the Folder and Associated files inside. The –recurse parameter will allow PowerShell to remove any child items without asking for permission.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top