diff --git a/src/System.Management.Automation/namespaces/FileSystemProvider.cs b/src/System.Management.Automation/namespaces/FileSystemProvider.cs index 830135f516c..460ae9a0355 100644 --- a/src/System.Management.Automation/namespaces/FileSystemProvider.cs +++ b/src/System.Management.Automation/namespaces/FileSystemProvider.cs @@ -3953,6 +3953,10 @@ private void CopyFileInfoItem(FileInfo file, string destinationPath, bool force, WriteError(new ErrorRecord(unAuthorizedAccessException, "CopyFileInfoItemUnauthorizedAccessError", ErrorCategory.PermissionDenied, file)); } } + catch (IOException ioException) + { + WriteError(new ErrorRecord(ioException, "CopyFileInfoItemIOError", ErrorCategory.WriteError, file)); + } } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Copy.Item.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Copy.Item.Tests.ps1 index bb71e8adec9..729d3b3d2e5 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Copy.Item.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Copy.Item.Tests.ps1 @@ -1,6 +1,19 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +Describe "Validate Copy-Item locally" -Tags "CI" { + It "Copy-Item has non-terminating error if destination is in use" -Skip:(!$IsWindows) { + Copy-Item -Path $env:windir\system32\cmd.exe -Destination TestDrive:\ + $cmd = Start-Process -FilePath TestDrive:\cmd.exe -PassThru + try { + { Copy-Item -Path $env:windir\system32\cmd.exe -Destination TestDrive:\ -ErrorAction SilentlyContinue } | Should -Not -Throw + } + finally { + $cmd | Stop-Process + } + } +} + # This is a Pester test suite to validate Copy-Item remotely using a remote session. # If PS Remoting is not available, do not run the suite.