You can easily delete files from PowerShell by using command “Remove-Item”. This article helps to you how to delete a file this command as below. Just open PowerShell prompt and execute the command.
PS C:\> Remove-Item C:\test\testFile.txt PS C:\>
How to Delete multiple files –
You can delete many files by this command and just need to add files name with separated by the comma. Looks below-
PS C:\> Remove-Item C:\dir1\file1, C:\dir1\file2, C:\dir2\file3 PS C:\>
How to Remove files with wild characters –
You can also use wildcards too with “Remove-item” and delete files in bulk.
If you use the above command and it deleted all files with csv extension. If the file does not exist, you will see an error when you command throw as shown below.
PS C:\> Remove-Item C:\dir1\FileThatDoesNotExist.txt Remove-Item : Cannot find path 'C:\dir1\FileThatDoesNotExist.txt' because it does not exist. At line:1 char:1 + Remove-Item C:\dir1\FileThatDoesNotExist.txt + ~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (C:\dir1\FileThatDoesNotExist.txt:String) [Remove-Item], ItemNotFoundException + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand
Read Also: How to Enable / Disable WiFi Connection
Last Updated on 3 years by Max