diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 7f80af1965..ba306edf9a 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -2599,10 +2599,7 @@ namespace Microsoft.PowerShell.Commands if (ShouldProcess(resource, action)) { - // Use the parent directory to create the sub-directory - - DirectoryInfo parentDirectory = new DirectoryInfo(parentPath); - DirectoryInfo result = parentDirectory.CreateSubdirectory(childName); + var result = Directory.CreateDirectory(Path.Combine(parentPath, childName)); 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 a2738d0428..f25667e494 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 @@ -1396,3 +1396,21 @@ Describe "Remove-Item UnAuthorized Access" -Tags "CI", "RequireAdminOnWindows" { Get-Content $errorFile | Should -BeExactly 'RemoveItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.RemoveItemCommand' } } + +Describe "Verify sub-directory creation under root" -Tag 'CI','RequireSudoOnUnix' { + BeforeAll { + $dirPath = "\TestDir-$((New-Guid).Guid)" + } + + AfterAll { + if(Test-Path $dirPath) + { + Remove-Item -Path $dirPath -Force -ErrorAction SilentlyContinue + } + } + + It "Can create a sub directory under root path" { + New-Item -Path $dirPath -ItemType Directory -Force > $null + $dirPath | Should -Exist + } +}