Strange error when attempting a foreach -parallel command while in a PS drive built in my profile. The error goes away when I switch to my C drive. Note that my S drive is in C. Will show definition:
PS [03/24/2020 07:18:32] C:\Users\a_s_p > get-psdrive s | fl
Name : S
Description :
Provider : Microsoft.PowerShell.Core\FileSystem
Root : C:\Users\a_s_p\Documents\3n
CurrentLocation :
PS [03/24/2020 07:12:02] S:\ > 1..5 | foreach-object -parallel {write-host $_}
PS [03/24/2020 07:12:03] S:\ > c:
PS [03/24/2020 07:14:56] C:\Users\a_s_p > 1..5 | foreach-object -parallel {write-host $_}
1
2
3
4
5
PS [03/24/2020 07:12:02] S:\ > 1..5 | foreach-object -parallel {write-host $_}
ForEach-Object: An unexpected error has occurred while processing ForEach-Object -Parallel input. This may mean that some of the piped input did not get processed. Error: System.Ma
nagement.Automation.DriveNotFoundException: Cannot find drive. A drive with the name 'S' does not exist.
at System.Management.Automation.SessionStateInternal.GetDrive(String name, Boolean automount)
at System.Management.Automation.SessionStateInternal.AutomountBuiltInDrive(String name)
at System.Management.Automation.SessionStateInternal.GetDrive(String name, Boolean automount)
at System.Management.Automation.SessionStateInternal.SetLocation(String path, CmdletProviderContext context, Boolean literalPath)
at System.Management.Automation.PSTasks.PSTaskBase.Start()
at System.Management.Automation.PSTasks.PSTaskPool.Add(PSTaskBase task)
at Microsoft.PowerShell.Commands.ForEachObjectCommand.
PS [03/24/2020 07:15:19] C:\Users\a_s_p > $psversiontable
Name Value
---- -----
PSVersion 7.0.0
PSEdition Core
GitCommitId 7.0.0
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
/cc @PaulHigin
Good find, @aspersram - can you please update the title of your report to a summary of its content?
We don't currently transfer current runspace state to the foreach parallel runspaces, and instead each loop iteration runs in a default runspace (except for current drive, which we do set). It is something we are considering as a new feature, which will likely be opt-in since it has perf implications.
For now I'll fix the error, and we can look at initializing loop runspaces from current runspace state in the future.
Done. Please let me know if the new title is descriptive enough.
Thank you. One other thing I’ve noticed; I have a directory called: ‘3n’ in my documents folder. In ps7, I cannot cd into it unless I enclose the dir name in quotes. If I type ‘cd 3n’, the ‘n’ isn’t recognized. I’m not in a psdrive, just C.
Is this just me?
-Mobile
On Mar 24, 2020, at 09:23, Paul Higinbotham notifications@github.com wrote:

We don't currently transfer current runspace state to the foreach parallel runspaces, and instead each loop iteration runs in a default runspace (except for current drive, which we do set). It is something we are considering as a new feature, which will likely be opt-in since it has perf implications.For now I'll fix the error, and we can look at initializing loop runspaces from current runspace state in the future.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
That's a known issue: https://github.com/PowerShell/PowerShell/issues/11626
I have a PR open which fixes that issue, which is pending review: https://github.com/PowerShell/PowerShell/pull/11634
Understood, thanks for the heads up.
Most helpful comment
We don't currently transfer current runspace state to the foreach parallel runspaces, and instead each loop iteration runs in a default runspace (except for current drive, which we do set). It is something we are considering as a new feature, which will likely be opt-in since it has perf implications.
For now I'll fix the error, and we can look at initializing loop runspaces from current runspace state in the future.