diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 830135f516..9b2d999e57 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -155,7 +155,17 @@ namespace Microsoft.PowerShell.Commands } else { - exactPath = Directory.GetFileSystemEntries(exactPath, item).First(); + // Use GetFileSystemEntries to get the correct casing of this element + var entries = Directory.GetFileSystemEntries(exactPath, item); + if (entries.Length > 0) + { + exactPath = entries.First(); + } + else + { + // If previous call didn't return anything, something failed so we just return the path we were given + return path; + } } }