This article describes how to delete files in PowerShell. In DOS, you can use the del command, and there are also rm commands in Linux. In PowerShell, you can easily get it done in one sentence!
In PowerShell, the cmdlet that deletes the file is Remove-Item. The Remove-Item cmdlet has the following alias: ri, rm, rmdir, del, erase, rd. If you want to ask how to remember or how these alias are, the editor will remind you that these alias are commands to delete files and delete directories under DOS and Linux systems. If you think about it carefully, isn’t it?
You can use the "get-help remove-item -full" command to view the complete help document of Remove-Item, as follows:
PS D:\> get-help remove-item -full
name
Remove-Item
summary
Delete the specified item.
grammar
Remove-Item [-LiteralPath] [-Credential] [-Exclud
e ] [-Filter] [-Force] [-Include ] [-Recurse]
[-Confirm] [-WhatIf] [-UseTransaction] []
Remove-Item [-Path] [-Credential] [-Exclude ng[]>] [-Filter] [-Force] [-Include ] [-Recurse] [-Confi
rm] [-WhatIf] [-UseTransaction] []
illustrate
Remove-Item cmdlet Delete one or more items. Since many providers support it, it can be deleted
Except for a number of different types of items, including files, directories, registry entries, variables, alias, and functions.
I won't copy the specific parameters, and those who are interested can read them by themselves. What Brother Hong wants to explain here is the emergence of -Exclude and -Include. You must understand at a glance that it can be operated in batches using wildcards. -Forece should be forced to delete, what should be deleted? Of course, it is a read-only file or a hidden file. -Recurse is a loop to delete contents in subfolders.
Delete the registry key
The command "remove-item hklm:\software\mycompany\OldApp -recurse" can delete the items under the specified registration path.
This article introduces so much about PowerShell using Remove-Item to delete files. I hope it will be helpful to you. Thank you!