diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 3423709d3cf..e81b1d13c97 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -2666,12 +2666,6 @@ private void CreateDirectory(string path, bool streamOutput) !string.IsNullOrEmpty(path), "The caller should verify path"); - // Get the parent path - string parentPath = GetParentPath(path, null); - - // The directory name - string childName = GetChildName(path); - ErrorRecord error = null; if (!Force && ItemExists(path, out error)) { @@ -2701,7 +2695,7 @@ private void CreateDirectory(string path, bool streamOutput) if (ShouldProcess(resource, action)) { - var result = Directory.CreateDirectory(Path.Combine(parentPath, childName)); + var result = Directory.CreateDirectory(path); if (streamOutput) { diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 index b365862f9d0..cdcc6c73018 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 @@ -1205,6 +1205,20 @@ Describe "Extended FileSystem Item/Content Cmdlet Provider Tests" -Tags "Feature $result.Name | Should -BeExactly $testDir } + It "Verify Directory creation when path relative to current PSDrive is empty" { + try { + $rootDir = New-Item "NewDirectory" -ItemType Directory -Force + $rootPath = $rootDir.FullName + $newPSDrive = New-PSDrive -Name "NewPSDrive" -PSProvider FileSystem -Root $rootPath + + $result = New-Item -Path "NewPSDrive:\" -ItemType Directory -Force + $result.FullName.TrimEnd("/\") | Should -BeExactly $newPSDrive.Root + } + finally { + Remove-PSDrive -Name "NewPSDrive" -Force -ErrorAction SilentlyContinue + } + } + It "Verify File + Value" { $result = New-Item -Path . -ItemType File -Name $testFile -Value "Some String" $content = Get-Content -Path $testFile