From 41e21d913487f936c3dac596971cae6aa2fee3bc Mon Sep 17 00:00:00 2001 From: KirtiRamchandani Date: Mon, 25 May 2026 00:21:52 +0530 Subject: [PATCH] Update New-Item unknown type message --- .../resources/FileSystemProviderStrings.resx | 2 +- .../FileSystem.Tests.ps1 | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/resources/FileSystemProviderStrings.resx b/src/System.Management.Automation/resources/FileSystemProviderStrings.resx index 360c2eceb7e..1314f6a3a0c 100644 --- a/src/System.Management.Automation/resources/FileSystemProviderStrings.resx +++ b/src/System.Management.Automation/resources/FileSystemProviderStrings.resx @@ -205,7 +205,7 @@ Directory {0} cannot be removed because it is not empty. - The type is not a known type for the file system. Only "file","directory" or "symboliclink" can be specified. + The type is not a known type for the file system. Only "file", "directory", "symboliclink", "junction", or "hardlink" can be specified. Cannot process the path because the specified path refers to an item that is outside the basePath. diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 index 3899ace7e3b..113abd3bcc6 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1 @@ -79,6 +79,17 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" { $newFile.Name | Should -BeExactly $newTestFile } + It "New-Item reports all supported file system item types for an unknown item type" { + $errorRecord = { + New-Item -Path (Join-Path $TestDrive "unknown-type") -ItemType UnknownType -ErrorAction Stop + } | Should -Throw -PassThru + + $errorRecord.FullyQualifiedErrorId | Should -BeExactly "Argument,Microsoft.PowerShell.Commands.NewItemCommand" + foreach ($itemType in '"file"', '"directory"', '"symboliclink"', '"junction"', '"hardlink"') { + $errorRecord.Exception.Message | Should -Match ([regex]::Escape($itemType)) + } + } + It "Verify Remove-Item for directory" { $existsBefore = Test-Path $testDir Remove-Item -Path $testDir -Recurse -Force