Serious Get-ChildItem performance degradation in v3
Votes from Connect: 25
Original Date Submitted: 10/4/2012 10:09:17 PM
Description:
Contact Information
Handle: Kirk Munro
Site Name: PowerShell
Feedback ID: 766100
Frequency: Always Happens
Regression: No, this is new to the most recent version
Problem Description:
When you invoke Get-ChildItem in PowerShell 3.0 with a path that does not exist, it searches for all files instead (wtf?). If you combine that with -Recurse and -ErrorAction SilentlyContinue in a script, you're facing a huge performance degradation that won't be easy to spot. Consider the two transcripts below. They show that a single Get-ChildItem call using a path that does not exist on my system takes 1302 times longer on v3 than it does on v2! I intentionally left -ErrorAction off of the command so that errors showing the scope of the search actually being performed by Get-ChildItem could be seen by the errors that identify the paths it is hitting when the command is run.
PowerShell 2 Transcript:
PS C:> Measure-Command {gci -li C:\MyFolder -Recurse -Force}
gci : Cannot find path 'C:\MyFolder' because it does not exist.
At line:1 char:21
+ Measure-Command {gci <<<< -li C:\MyFolder -Recurse -Force}
+ CategoryInfo : ObjectNotFound: (C:\MyFolder:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 29
Ticks : 292580
TotalDays : 3.38634259259259E-07
TotalHours : 8.12722222222222E-06
TotalMinutes : 0.000487633333333333
TotalSeconds : 0.029258
TotalMilliseconds : 29.258
PowerShell 3 Transcript:
PS C:> Measure-Command {gci -li C:\MyFolder -Recurse -Force}
gci : Access to the path 'C:\Documents and Settings' is denied.
At line:1 char:18
+ Measure-Command {gci -li C:\MyFolder -Recurse -Force}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\Documents and Settings:String) [Get-ChildItem], UnauthorizedAccess
Exception
+ FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
<snip>
gci : Access to the path 'C:\Users\Public\Documents\My Videos' is denied.
At line:1 char:18
+ Measure-Command {gci -li C:\MyFolder -Recurse -Force}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\Users\Public\Documents\My Videos:String) [Get-ChildItem], Unauthor
izedAccessException
+ FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
gci : Access to the path 'C:\Windows\System32\LogFiles\WMI\RtBackup' is denied.
At line:1 char:18
+ Measure-Command {gci -li C:\MyFolder -Recurse -Force}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\Windows\Syst...es\WMI\RtBackup:String) [Get-ChildItem], Unauthoriz
edAccessException
+ FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
Days : 0
Hours : 0
Minutes : 0
Seconds : 38
Milliseconds : 109
Ticks : 381091208
TotalDays : 0.000441077787037037
TotalHours : 0.0105858668888889
TotalMinutes : 0.635152013333333
TotalSeconds : 38.1091208
TotalMilliseconds : 38109.1208
Product Studio item created by Connect Synchronizer due to creation of feedback ID 766100 (http://connect.microsoft.com/PowerShell/feedback/ViewFeedback.aspx?FeedbackID=766100).
Repro Steps:
gci -li C:\DoesNotExist -Recurse
Expected Results:
This should return immediately with an error indicating that C:\DoesNotExist does not exist, just like it did in PowerShell 2.0.
Internal BugId: 3858
