diff --git a/src/System.Management.Automation/engine/hostifaces/PSTask.cs b/src/System.Management.Automation/engine/hostifaces/PSTask.cs index 45b3e944917..a4bc49a7af2 100644 --- a/src/System.Management.Automation/engine/hostifaces/PSTask.cs +++ b/src/System.Management.Automation/engine/hostifaces/PSTask.cs @@ -449,6 +449,10 @@ public void Start(Runspace runspace) Runspace.DefaultRunspace = runspace; runspace.ExecutionContext.SessionState.Internal.SetLocation(_currentLocationPath); } + catch (DriveNotFoundException) + { + // Allow task to run if current drive is not available. + } finally { Runspace.DefaultRunspace = oldDefaultRunspace; diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Foreach-Object-Parallel.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Foreach-Object-Parallel.Tests.ps1 index 2e6c5404fde..63b6236b756 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Foreach-Object-Parallel.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Foreach-Object-Parallel.Tests.ps1 @@ -104,6 +104,20 @@ Describe 'ForEach-Object -Parallel Basic Tests' -Tags 'CI' { $parallelScriptLocation = 1..1 | ForEach-Object -Parallel { $PWD } $parallelScriptLocation.Path | Should -BeExactly $PWD.Path } + + It 'Verifies no terminating error if current working drive is not found' { + $oldLocation = Get-Location + try + { + New-PSDrive -Name ZZ -PSProvider FileSystem -Root $TestDrive + Set-Location -Path 'ZZ:' + { 1..1 | ForEach-Object -Parallel { $_ } } | Should -Not -Throw + } + finally + { + Set-Location -Path $oldLocation + } + } } Describe 'ForEach-Object -Parallel common parameters' -Tags 'CI' {