mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix foreach parallel when current drive is not available (#12197)
This commit is contained in:
@@ -449,6 +449,10 @@ namespace System.Management.Automation.PSTasks
|
||||
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;
|
||||
|
||||
+14
@@ -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' {
|
||||
|
||||
Reference in New Issue
Block a user