Windows PowerShell Remove-Item
Windows PowerShell Remove-Item (Del)
Warning: I have been unusually cautious on this page, because if a delete script goes wrong and forces a delete of the wrong files it could be disastrous. Hundreds of people will succeed no trouble, but I do worry about that one person who gets the wrong end of Remove-Item and deletes the wrong files.
Note 1: There is no PowerShell Delete-Item cmdlet it's Remove-Item
Windows PowerShell Remove-Item Progression
Delete-Item Safety Measures
Before deleting files or erasing stuff, I advise you to see what happens with Get-Item before you unleash Remove-Item.
When testing a deletion script my idea is to create folder called C:\GuyStuff\ then create a few files in this folder.
PowerShell Script To Create Test Folder and Files
This is in preparation, my idea is that we delete test files and not existing ones.
# PowerShell Create Folder and Files
#PowerShell Script to List Files
#PowerShell Remove-Item Example to Delete Files
Note 2: This script features the -force switch to zap protected files.
Note 3: The verb is remove, there is no such built-In cmdlet as Delete-Item.
Note 4: For an advanced real-life Remove-Item script see here.
Here is an utility where you can review firewall settings such as access control lists (ACL), or troubleshoot problems with network address translation (NAT).
Other reasons to download this SolarWinds Firewall Browser include managing requests to change your firewall settings, testing firewall rules before you go live, and querying settings with the browser's powerful search options.
Guy recommends that you download a copy of the SolarWinds free Firewall Browser.
One of my very few warnings is before you use Remove-Item for a real task append the -WhatIf switch.
#PowerShell Script to Mimic Deleting Files
PowerShell's Remove-Item Parameters
# PowerShell Remove-Item Parameters
Checking the help file will reveal useful parameters, for instance -force -exclude. Dare I tell you that there is also -recurse, but in the case of Remove-Item, use that parameter with the utmost care.
Remove-Item Aliases Del and Erase
Check the aliases with this little script:
# PowerShell Remove-Item Alias
Note 5: There is no actual PowerShell Delete-Item cmdlet, however, there is a 'del' alias.
With Microsoft, there are always at least three ways of doing everything, what seems like redundancy when you are an expert, seems like perspective when you are a beginner. As you increase your range of PowerShell commands, keep an eye out for another PowerShell Alias, for example gci (Get-Childitem).
This Engineer's Toolset v10 provides a comprehensive console of 50 utilities for troubleshooting computer problems. Guy says it helps me monitor what's occurring on the network, and each tool teaches me more about how the underlying system operates.
There are so many good gadgets; it's like having free rein of a sweetshop. Thankfully the utilities are displayed logically: monitoring, network discovery, diagnostic, and Cisco tools. Try the SolarWinds Engineer's Toolset now!
Real-life Tasks for Remove-Item
Microsoft's Windows operating systems create temporary files, let us use PowerShell's Remove-Item to clean up these unwanted files.
Researching Similar PowerShell Cmdlets
# PowerShell Item Cmdlet Research
As we know there is a Get-Item and a New-Item cmdlet, but you may not realize there is a Copy-Item cmdlet. PowerShell -Noun or -verb research always throws up at least one surprise. In this case it's the absence of a PowerShell Delete-Item cmdlet, use Remove-Item instead.
Summary of PowerShell Remove-Item
The syntax for Remove-Item is straightforward. I urge you to take precautions because if you get the path wrong, the effect could be devastating, especially if you are gung-ho with the -force and the -recurse parameter. For this reason I suggest that you check with Get-Item before you actually use Remove-Item, even then consider the -whatIf switch if there is any doubt.
If you like this page then please share it with your friends
See more PowerShell examples for syntax constructions
Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.