PowerShell / PowerShell/PowerShell
Write-Debug ignores Debug switch in Foreach-Object Parallel block
Open
Nobody has claimed this yet.
Needs-Triage
- Dominant language
- C#
- Stars
- 55.5k
- Forks
- 8.5k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 88
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
Run this script with two identical blocks of code except for the "Parallel" option.
Write-Host 'Test 1 - non-parallel'
$DebugPreference = 'SilentlyContinue'
1..2 |
ForEach-Object {
Write-Debug "Item $_`: Write-Debug"
Write-Debug "Item $_`: Write-Debug -Debug" -Debug
Write-Debug "Item $_`: Write-Debug -Debug:`$true" -Debug:$true
Write-Debug "Item $_`: Write-Debug -Debug:`$false" -Debug:$false
}
Write-Host 'Test 2 - parallel'
$DebugPreference = 'SilentlyContinue'
1..2 |
ForEach-Object -Parallel {
Write-Debug "Item $_`: Write-Debug"
Write-Debug "Item $_`: Write-Debug -Debug" -Debug
Write-Debug "Item $_`: Write-Debug -Debug:`$true" -Debug:$true
Write-Debug "Item $_`: Write-Debug -Debug:`$false" -Debug:$false
}
Write-Host 'Done'
Expected behavior
Test 1 - non-parallel
DEBUG: Item 1: Write-Debug -Debug
DEBUG: Item 1: Write-Debug -Debug:$true
DEBUG: Item 2: Write-Debug -Debug
DEBUG: Item 2: Write-Debug -Debug:$true
Test 2 - parallel
DEBUG: Item 1: Write-Debug -Debug
DEBUG: Item 1: Write-Debug -Debug:$true
DEBUG: Item 2: Write-Debug -Debug
DEBUG: Item 2: Write-Debug -Debug:$true
Done
Actual behavior
Test 1 - non-parallel
DEBUG: Item 1: Write-Debug -Debug
DEBUG: Item 1: Write-Debug -Debug:$true
DEBUG: Item 2: Write-Debug -Debug
DEBUG: Item 2: Write-Debug -Debug:$true
Test 2 - parallel
Done
Error details
NA
Environment data
Name Value
---- -----
PSVersion 7.4.3
PSEdition Core
GitCommitId 7.4.3
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided reproduction script and compare Write-Debug behavior in ordinary and ForEach-Object -Parallel blocks. Trace the ForEach-Object -Parallel and Write-Debug entry points to determine why the Debug switch is ignored, then verify that the parallel block produces the expected debug lines while respecting DebugPreference.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- shell
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100