Repository navigation
Closed
Labels
Resolution-Won't FixThe issue won't be fixed, possibly due to compatibility reason.The issue won't be fixed, possibly due to compatibility reason.WG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.built-in PowerShell providers such as FileSystem, Certificates, Registry, etc.WG-ReviewedA Working Group has reviewed this and made a recommendationA Working Group has reviewed this and made a recommendation
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
This is a serious problem that can result in unwanted deletion of both files and subdirectories.
Related:
- Remove-Item -Recurse with an -Include or -Filter argument mistakenly tries to remove the directory itself #16153
Remove-Itemshould provide-Fileparameter #20637
# Create and switch to a temp. dir.
Push-Location ($tmpDir = New-Item -Force -Type Directory (Join-Path temp: $PID))
# Create two sample files and a sample subdir.
'1.txt', '2.csv' | % { '' > $_ }
$null = New-Item -Force -Type Directory subdir
# Use -Filter *.txt alone
Remove-Item * -Filter *.txt -WhatIf
'---'
# Use -Filter *.txt with -Recurse
Remove-Item * -Filter *.txt -Recurse -WhatIf
# Clean up
Pop-Location
$tmpDir | Remove-Item -Recurse Expected behavior
What if: Performing the operation "Remove File" on target "/var/folders/_t/8x3_gp2n6lb1mpg106v6vsvc0000gn/T/64474/1.txt".
---
What if: Performing the operation "Remove File" on target "/var/folders/_t/8x3_gp2n6lb1mpg106v6vsvc0000gn/T/64474/1.txt".Actual behavior
What if: Performing the operation "Remove File" on target "/var/folders/_t/8x3_gp2n6lb1mpg106v6vsvc0000gn/T/64474/1.txt".
---
What if: Performing the operation "Remove Directory" on target "/var/folders/_t/8x3_gp2n6lb1mpg106v6vsvc0000gn/T/64474/subdir".
What if: Performing the operation "Remove File" on target "/var/folders/_t/8x3_gp2n6lb1mpg106v6vsvc0000gn/T/64474/1.txt".
What if: Performing the operation "Remove File" on target "/var/folders/_t/8x3_gp2n6lb1mpg106v6vsvc0000gn/T/64474/2.csv".That is, all items were targeted when -Recurse was added
Error details
No response
Environment data
PowerShell 7.4.0-rc.1Visuals
No response
Metadata
Metadata
Assignees
Labels
Resolution-Won't FixThe issue won't be fixed, possibly due to compatibility reason.The issue won't be fixed, possibly due to compatibility reason.WG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.built-in PowerShell providers such as FileSystem, Certificates, Registry, etc.WG-ReviewedA Working Group has reviewed this and made a recommendationA Working Group has reviewed this and made a recommendation
Activity
[-]`Remove-Item`: adding `-Recurse` when `-Filter` is also used ignores the filter[/-][+]`Remove-Item`: adding `-Recurse` when `-Filter` is also used ignores the filter, targets *all* items.[/+]SeeminglyScience commentedon Apr 15, 2024
The Engine WG discussed this. While we agree that it is a bug and would ideally work more like
-Includedoes, we are worried about making a change in this particularly sensitive area and are marking this aswontfix.microsoft-github-policy-service commentedon Apr 16, 2024
This issue has been marked as won't fix and has not had any activity for 1 day. It has been closed for housekeeping purposes.
microsoft-github-policy-service commentedon Apr 16, 2024
📣 Hey Michael Klement (@mklement0), how did we do? We would love to hear your feedback with the link below! 🗣️
🔗 https://aka.ms/PSRepoFeedback