Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No WhatIf output in Foreach-Object -Parallel #14984

Closed
tleepa opened this issue Mar 10, 2021 · 8 comments
Closed

No WhatIf output in Foreach-Object -Parallel #14984

tleepa opened this issue Mar 10, 2021 · 8 comments
Labels
Issue-Enhancement the issue is more of a feature request than a bug Needs-Triage The issue is new and needs to be triaged by a work group. Resolution-No Activity Issue has had no activity for 6 months or more WG-Cmdlets-Core cmdlets in the Microsoft.PowerShell.Core module

Comments

@tleepa
Copy link

tleepa commented Mar 10, 2021

When I run a command with -WhatIf switch within a Foreach-Object loop, it shows the "What if: ..." output.
When doing the same with -Parallel, this output is not shown.

If there is Write-Host statement in loop body, it is visible in both cases.

Is there anything I can do about it? Is it a bug, or by design?

Steps to reproduce

Prepare some directories:

("test1", "test2", "test3") | ForEach-Object { New-Item -Path .\$_ }

Then remove them with -WhatIf switch using -Parallel

("test1", "test2", "test3") | ForEach-Object -Parallel { Remove-Item -Path .\$_ -WhatIf }

Expected behavior

Should be the same as running:

("test1", "test2", "test3") | ForEach-Object { Remove-Item -Path .\$_ -WhatIf }
What if: Performing the operation "Remove File" on target "<current dir>\test1".
What if: Performing the operation "Remove File" on target "<current dir>\test2".
What if: Performing the operation "Remove File" on target "<current dir>\test3".

Actual behavior

<No ouput>

Environment data

❯ $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.2
PSEdition                      Core
GitCommitId                    7.1.2
OS                             Microsoft Windows 10.0.19041
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
@tleepa tleepa added the Needs-Triage The issue is new and needs to be triaged by a work group. label Mar 10, 2021
@daxian-dbw daxian-dbw added the WG-Remoting PSRP issues with any transport layer label Mar 10, 2021
@TravisEz13 TravisEz13 added Issue-Enhancement the issue is more of a feature request than a bug and removed Needs-Triage The issue is new and needs to be triaged by a work group. labels Mar 17, 2021
@TravisEz13 TravisEz13 added this to the Future milestone Mar 17, 2021
@TravisEz13
Copy link
Member

Remoting working group: We still need to figure out why this is not coming through and possibly add a feature.

Do you have a real-life scenario that you need to run whatif in parallel?

@tleepa
Copy link
Author

tleepa commented Mar 18, 2021

Well, I am using parallel to loop over actions in Azure, that can be time-consuming.
I am using a -Noop switch in my scripts and run some commands using -WhatIf:$Noop. This way I don't have to test for the switch value and run different commands.
But it is not a deal breaker :)

@TravisEz13
Copy link
Member

TravisEz13 commented Mar 23, 2021

Copy-Item ./test.ps1 ./test2.ps1 -WhatIf *> test.txt
What if: Performing the operation "Copy File" on target "Item: /Users/******/git/powershell/test.ps1 Destination: /Users/********/git/powershell/test2.ps1".

I did a little investigation. It appears that -whatif writes directly to the host and is not redirectable.

I'll let @PaulHigin speak for what this means for foreach-object -parallel but I don't think it is good.

@TravisEz13 TravisEz13 added the Needs-Triage The issue is new and needs to be triaged by a work group. label Mar 23, 2021
@PaulHigin PaulHigin removed the Needs-Triage The issue is new and needs to be triaged by a work group. label Jun 8, 2021
@PaulHigin PaulHigin removed this from the Future milestone Jun 8, 2021
@JustinGrote
Copy link
Contributor

@TravisEz13 this would be solved by: #9870

@StevenBucher98 StevenBucher98 added Needs-Triage The issue is new and needs to be triaged by a work group. and removed Needs-Triage 🔍 labels May 23, 2022
@PaulHigin PaulHigin added WG-Cmdlets-Core cmdlets in the Microsoft.PowerShell.Core module and removed WG-Remoting PSRP issues with any transport layer labels Jun 13, 2022
Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

2 similar comments
Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Resolution-No Activity Issue has had no activity for 6 months or more label Nov 16, 2023
Copy link
Contributor

This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement the issue is more of a feature request than a bug Needs-Triage The issue is new and needs to be triaged by a work group. Resolution-No Activity Issue has had no activity for 6 months or more WG-Cmdlets-Core cmdlets in the Microsoft.PowerShell.Core module
Projects
None yet
Development

No branches or pull requests

6 participants