Get-ChildItem \serversharedir_doesnt_exist
Get-ChildItem \serversharedir_doesnt_exist -Recurse
Both cases should return an ItemNotFoundException
Non-recursive case behaves correctly
Recursive case just appears to hang / run forever
@juneb confirmed the behavior
Name Value
---- -----
PSVersion 5.1.14393.576
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.576
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Just to check - maybe it's not hung, but it might be enumerating the share.
I tried
Only case 3 seems to hang, but I noticed I eventually got a DirUnauthorizedAccessError on a file/directory that I wouldn't have expected to see, so it looks like we're just enumerating the file system.
We just ran into this today on a local drive. With a little testing, the results got even stranger. I was able to identify 2 scenarios with unexpected behavior.
The first is trying to get a folder that does not exist with a trailing backslash.
PS:> Get-ChildItem -Path C:\Windows\missing_folder\ -Recurse
Get-ChildItem : Cannot find path 'C:\Windows\m' because it does not exist.
PS:> Get-ChildItem -Path C:\Windows\other_missing_folder\ -Recurse
Get-ChildItem : Cannot find path 'C:\Windows\o' because it does not exist.
You will notice that it failed to find a folder called C:\Windows\m that I did not specify. The name of the folder is always the first character of the missing folder name. If the folder C:\Windows\m does exist, it will not throw an error and instead silently finish with no results. (It will not return the contents of that folder though).
The second unexpected behavior is when you don't use the trailing slash. The entire parent folder is recursively walked.
PS:> Get-ChildItem -Path C:\Windows\missing_folder -Recurse
Get-ChildItem : Access to the path 'C:\Windows\appcompat\Programs' is denied.
Get-ChildItem : Access to the path 'C:\Windows\CSC' is denied.
Get-ChildItem : Access to the path 'C:\Windows\Logs\SystemRestore' is denied.
I used the c:\windows folder in this example because there are several subfolders that will give you an access denied.
Most helpful comment
We just ran into this today on a local drive. With a little testing, the results got even stranger. I was able to identify 2 scenarios with unexpected behavior.
The first is trying to get a folder that does not exist with a trailing backslash.
You will notice that it failed to find a folder called
C:\Windows\mthat I did not specify. The name of the folder is always the first character of the missing folder name. If the folderC:\Windows\mdoes exist, it will not throw an error and instead silently finish with no results. (It will not return the contents of that folder though).The second unexpected behavior is when you don't use the trailing slash. The entire parent folder is recursively walked.
I used the
c:\windowsfolder in this example because there are several subfolders that will give you an access denied.