When it comes to managing files on Windows 11, PowerShell is one of the most powerful tools in your toolkit. Whether you need to delete a single file, an entire directory, or hundreds of files automatically, PowerShell can do it all with just a few commands.
In this guide, we’ll walk you through how to delete files and folders using PowerShell safely and efficiently — from basic commands to advanced automation.
Delete Files and Folders Using PowerShell in Windows 11
Before you begin, make sure you have:
- Administrator privileges (for system files or protected folders)
- PowerShell (built into Windows 11 by default)
You can open PowerShell by pressing Windows + X → Terminal (Admin) or searching for “PowerShell” in the Start Menu.
Step 1: Open PowerShell
To open PowerShell with the right permissions:
- Click Start → search PowerShell.
- Right-click Windows PowerShell → select Run as Administrator.
- If prompted by User Account Control (UAC), click Yes.
You’ll now see a blue PowerShell window — your command hub for file operations.
Step 2: Delete a Single File
To delete a single file, use the Remove-Item cmdlet — it’s the PowerShell equivalent of the “Delete” button.
Syntax:
Remove-Item "C:\Path\To\File.txt"
Example:
Remove-Item "C:\Users\John\Documents\old_report.txt"
This command deletes the specified file immediately — no confirmation prompt by default.
Tip: Always double-check your file path before pressing Enter. Deletions are permanent (they don’t go to the Recycle Bin).
Step 3: Delete Multiple Files
You can also delete multiple files in one go using wildcards (*).
Example 1: Delete all .log files in a folder
Remove-Item "C:\Logs\*.log"
Example 2: Delete all files in a folder (but not subfolders)
Remove-Item "C:\Temp\*"
Tip: If you want PowerShell to ask before deleting each file, add the -Confirm flag:
Remove-Item "C:\Temp\*" -Confirm
Step 4: Delete an Entire Folder
To delete a folder and everything inside it, use the -Recurse parameter.
Syntax:
Remove-Item "C:\Path\To\Folder" -Recurse
Example:
Remove-Item "C:\Users\John\Downloads\OldProjects" -Recurse
This command deletes the folder along with all files and subfolders inside it.
Warning: This action is permanent — PowerShell doesn’t move deleted folders to the Recycle Bin.
Step 5: Force Delete Protected Files and Folders
Sometimes Windows protects files that are in use or have restricted permissions. To override this, use the -Force flag.
Example:
Remove-Item "C:\System\TempFiles" -Recurse -Force
This forces deletion even for read-only or hidden files.
Caution: Be very careful with -Force — it ignores restrictions and deletes everything without prompting.
Step 6: Delete Files by Type or Date
You can combine PowerShell’s Get-ChildItem with Remove-Item to target specific files.
Example 1: Delete all .tmp files in a folder
Get-ChildItem "C:\Temp" -Filter *.tmp | Remove-Item
Example 2: Delete files older than 30 days
Get-ChildItem "C:\Backups" | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-30) } | Remove-Item
This command automatically finds and removes old files — perfect for cleaning up backup folders.
Step 7: Confirm Before Deleting Files (Safe Mode)
If you want to stay on the safe side, you can preview what files will be deleted before actually removing them.
Step 1: List files
Get-ChildItem "C:\Logs\*.log"
Step 2: If the list looks correct, then run:
Get-ChildItem "C:\Logs\*.log" | Remove-Item
This ensures you only delete what you intend to.
Step 8: Delete Read-Only Files
PowerShell can also handle read-only attributes. To remove read-only files, use the -Force flag.
Example:
Remove-Item "C:\Reports\old_data.csv" -Force
If you’re deleting an entire directory of read-only files:
Remove-Item "C:\Reports\Archive" -Recurse -Force
Step 9: Use the -WhatIf Parameter for Testing
Want to see what would happen before deleting anything?
Add the -WhatIf flag — it simulates deletion without actually removing files.
Example:
Remove-Item "C:\Temp\*" -Recurse -WhatIf
You’ll get output like:
What if: Performing the operation "Remove File" on target "C:\Temp\example.txt".
Once you confirm everything looks right, rerun the same command without -WhatIf.
Step 10: Automate File Cleanup with PowerShell Script
You can automate cleanup tasks by saving your commands into a .ps1 script file.
Example script: cleanup.ps1
# Delete temp files older than 7 days
$path = "C:\Temp"
Get-ChildItem $path | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-7) } | Remove-Item -Recurse -Force
To run the script:
powershell -ExecutionPolicy Bypass -File "C:\Scripts\cleanup.ps1"
Pro Tip: You can schedule this script to run automatically using Task Scheduler — great for regular maintenance.
Step 11: Delete Files with Specific Patterns
If you want to target files with specific patterns in the name, use -like with Where-Object.
Example:
Get-ChildItem "C:\Logs" | Where-Object { $_.Name -like "*error*" } | Remove-Item
This deletes all files in the Logs folder that contain the word “error.”
Wrapping Up
And that’s it — you’ve learned how to delete files and folders using PowerShell in Windows 11!
From removing single files to automating large cleanups, PowerShell gives you complete control — faster, safer, and more precise than using File Explorer.
Whether you’re a developer managing builds, an IT admin cleaning up temp folders, or just someone organizing your PC, these commands will help you stay efficient and organized.