Repository navigation
Open
Labels
Needs-TriageThe issue is new and needs to be triaged by a work group.WG-Enginecore PowerShell engine, interpreter, and runtimeWG-NeedsReviewNeeds a review by the labeled Working Group
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
> 1..100 | % { New-Item -Type Directory -Force "C:\Temp\repro\$_\$(1..100 -join '\')" | Out-Null }
> Remove-Item "C:\Temp\repro" -Recurse -ForceExpected behavior
`C:\Temp\repro` is removedActual behavior
Remove-Item: The directory is not empty. : 'C:\Temp\repro\1\1\2\3\4\5\6'.
Remove-Item: The directory is not empty. : 'C:\Temp\repro\1\1\2\3\4\5'.
Remove-Item: The directory is not empty. : 'C:\Temp\repro\1\1\2\3\4'.
Remove-Item: The directory is not empty. : 'C:\Temp\repro\1\1\2\3'.
Remove-Item: The directory is not empty. : 'C:\Temp\repro\1\1\2'.
Remove-Item: The directory is not empty. : 'C:\Temp\repro\1\1'.
Remove-Item: The directory is not empty. : 'C:\Temp\repro\1'.
Remove-Item: The directory is not empty. : 'C:\Temp\repro\10\1\2\3\4\5\6\7\8\9\10\11\12\13\14\15\16\17\18\19\20\21\22\23\24\25\26\27\28\29\30\31\32\33\34\35\36\37\38\39\40\41\42\43\44\45\46\47\48\49\50\51\52\53\54\55\56\57\58\59\60\61'.
... and etc.Error details
> get-error
Exception :
Type : System.IO.IOException
TargetSite :
Name : RemoveDirectoryInternal
DeclaringType : [System.IO.FileSystem]
MemberType : Method
Module : System.Private.CoreLib.dll
Message : The directory is not empty. : 'C:\Temp\repro'.
Source : System.Private.CoreLib
HResult : -2147024751
StackTrace :
at System.IO.FileSystem.RemoveDirectoryInternal(String fullPath, Boolean topLevel, Boolean allowDirectoryNotEmpty)
at System.IO.DirectoryInfo.Delete()
at Microsoft.PowerShell.Commands.FileSystemProvider.RemoveFileSystemItem(FileSystemInfo fileSystemInfo, Boolean force)
TargetObject : C:\Temp\repro
CategoryInfo : WriteError: (C:\Temp\repro:DirectoryInfo) [Remove-Item], IOException
FullyQualifiedErrorId : RemoveFileSystemItemIOError,Microsoft.PowerShell.Commands.RemoveItemCommand
ErrorDetails :
InvocationInfo :
MyCommand : Remove-Item
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 36
Line : Remove-Item "C:\Temp\repro" -Recurse -Force -ProgressAction Continue
Statement : Remove-Item "C:\Temp\repro" -Recurse -Force -ProgressAction Continue
PositionMessage : At line:1 char:1
+ Remove-Item "C:\Temp\repro" -Recurse -Force -ProgressAction Continue
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : Remove-Item
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :
0
1Environment data
Name Value
---- -----
PSVersion 7.6.2
PSEdition Core
GitCommitId 7.6.2
OS Microsoft Windows 10.0.17763
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.4
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Remove-Item "C:\Temp\repro" -Recurse -Force -ProgressAction SilentlyContinue does not help, only $ProgressPreference = 'SilentlyContinue' works.
Guess this is somewhat dependant on the storage performance / load on the box, manged to repro it only on some machines.
Process Monitor shows GetTotalFiles worker thread scanning the file tree while the pipeline thread tries to SetDispositionInformationFile Delete: True but gets back NOT EMPTY
Metadata
Metadata
Assignees
Labels
Needs-TriageThe issue is new and needs to be triaged by a work group.WG-Enginecore PowerShell engine, interpreter, and runtimeWG-NeedsReviewNeeds a review by the labeled Working Group
Activity
mklement0 commentedon Aug 7, 2026
AI tells me that
Microsoft Windows 10.0.17763(from your environment data) implies "Windows 10 version 1809 (the "October 2018 Update")."This would explain the asynchronous behavior, as it predates the fix mentioned in the initial post of #8211 (Windows 10 version 1909 or later)
Indeed, I cannot reproduce your symptom on PowerShell Core v7.6.4 (.NET 10.0.10) on Microsoft Windows 11 Pro (ARM 64-bit Processor; Version 25H2, OS Build: 26200.8737)
ajansveld commentedon Aug 7, 2026
Good catch, this is in fact Windows Server 2019 (supported until 2029, so this definitely needs a fix).
mklement0 commentedon Aug 7, 2026
Since Windows 10 and Windows Server 2019 share the same foundation and given how old Windows 10 version 1809 is, I strongly suspect (but don't know for sure) that Windows Server 2019 has since seen updates in which the problem is fixed.
ajansveld commentedon Aug 17, 2026
Which problem? Apparently not this one, the hosts in question are fully patched.
mklement0 commentedon Aug 17, 2026
The problem of the file system-item deletion system APIs having historically been inherently asynchronous, by (problematic) design.
Speaking in no official capacity whatsoever, my hunch is:
Given the age of the affected platform and given that the problem has been resolved in more recent versions, it is highly unlikely that action will be taken, especially on the PowerShell side (compensating for potentially undesired behavior of system-level APIs is not usually done).
mklement0 commentedon Aug 17, 2026
P.S.: If you want a - suboptimal - workaround, see this Stack Overflow answer.
Tadas commentedon Aug 20, 2026
Just to be clear about the environment, this is on Server 2019 with August 11 2026—KB5120238 (OS Build 17763.9121) patch. Whatever the exact history on the OS side, this build clearly doesn't have the newer delete behaviour (which is fine).
With that said, this is very clearly a PowerShell regression introduced in 7.5 by the Remove-Item progress bar:
$ProgressPreference = 'SilentlyContinue': no failures.To me feels like this is getting lost in the thread:
Task.Run(GetTotalFiles), so on OS without the newer delete behaviour the intermittent problem from On Windows, Remove-Item fails intermittently with -Recurse and is unexpectedly asynchronous itself #8211 becomes near-deterministic.PowerShell/src/System.Management.Automation/namespaces/FileSystemProvider.cs
Lines 2905 to 2908 in 7acb292
On top of that, the fact that
-ProgressActionisn't respected is another problem with the implementation.mklement0 commentedon Aug 20, 2026
I don't think it is fine: you'll still see failures - even if less frequently so than with the 7.5+ progress bar in the picture (I'm trusting your analysis there).
To put it differently: the only robust fix is to either:
(a) fix the system APIs by making them synchronous - which is true since at least Windows 11 (as well as Windows 10 versions 1909 or later) and - if I were to guess - since at least Windows Server 2022.
(b) compensate for the system API behavior on the PowerShell side.
As noted before, (b) strikes me as highly unlikely, as does retrofitting the new synchronous behavior at the level of the system calls to Windows Server 2019.
Tadas commentedon Aug 21, 2026
Oh yeah I see your point, I was too focused on this particular scenario and forgot that something else could have a handle open.
I don't think it is a pass to make it worse, though. Again, Server 2019 is still supported and we've not hit the issue in 7.4 (which annoyingly is about to hit end-of-support).
I share this sentiment. But it doesn't seem like "new" issues are likely to get looked at either.