Skip to content

Preference variables don't propagate to script block of ForEach-Object -Parallel #14672

Closed

Description

Steps to reproduce

$ErrorActionPreference = 'Stop'
$WhatIfPreference      = 'True'
$DebugPreference       = 'Continue'
$VerbosePreference     = 'Continue'
$WarningPreference     = 'Ignore'
$ConfirmPreference     = 'None'

@(1) | ForEach-Object -Parallel {
    [PSCustomObject] @{ Variable = 'ErrorActionPreference'; Expected = $using:ErrorActionPreference; Actual = $ErrorActionPreference }
    [PSCustomObject] @{ Variable = 'WhatIfPreference'; Expected = $using:WhatIfPreference; Actual = $WhatIfPreference }
    [PSCustomObject] @{ Variable = 'DebugPreference'; Expected = $using:DebugPreference; Actual = $DebugPreference }
    [PSCustomObject] @{ Variable = 'VerbosePreference'; Expected = $using:VerbosePreference; Actual = $VerbosePreference }
    [PSCustomObject] @{ Variable = 'WarningPreference'; Expected = $using:WarningPreference; Actual = $WarningPreference }
    [PSCustomObject] @{ Variable = 'ConfirmPreference'; Expected = $using:ConfirmPreference; Actual = $ConfirmPreference }
}

@(1) | ForEach-Object -Parallel {
    [CmdLetBinding()] Param()
    [PSCustomObject] @{ Variable = 'ErrorActionPreference'; Expected = $using:ErrorActionPreference; Actual = $ErrorActionPreference }
    [PSCustomObject] @{ Variable = 'WhatIfPreference'; Expected = $using:WhatIfPreference; Actual = $WhatIfPreference }
    [PSCustomObject] @{ Variable = 'DebugPreference'; Expected = $using:DebugPreference; Actual = $DebugPreference }
    [PSCustomObject] @{ Variable = 'VerbosePreference'; Expected = $using:VerbosePreference; Actual = $VerbosePreference }
    [PSCustomObject] @{ Variable = 'WarningPreference'; Expected = $using:WarningPreference; Actual = $WarningPreference }
    [PSCustomObject] @{ Variable = 'ConfirmPreference'; Expected = $using:ConfirmPreference; Actual = $ConfirmPreference }
}

Expected behavior

Variable              Expected           Actual
--------              --------           ------
ErrorActionPreference     Stop             Stop
WhatIfPreference          True             True
DebugPreference       Continue         Continue
VerbosePreference     Continue         Continue
WarningPreference       Ignore           Ignore
ConfirmPreference         None             None

Actual behavior

Variable              Expected           Actual
--------              --------           ------
ErrorActionPreference     Stop         Continue
WhatIfPreference          True            False
DebugPreference       Continue SilentlyContinue
VerbosePreference     Continue SilentlyContinue
WarningPreference       Ignore         Continue
ConfirmPreference         None             High

Environment data

Name                           Value
----                           -----
PSVersion                      7.1.1
PSEdition                      Core
GitCommitId                    7.1.1
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Needs-Triage
    on Jan 27, 2021
  2. changed the title [-]Some Preference variables are not propagated to script block of ForEach-Object -Parallel[/-] [+]Preference variables don't propagate to script block of ForEach-Object -Parallel[/+] on Jan 27, 2021
  3. jborean93 commented on Jan 27, 2021

    @jborean93
    Collaborator

    Looks to be a duplicate of #14602 and #12240

  4. added
    WG-Remoting
    on Jan 27, 2021
  5. added
    Issue-Enhancement
    and removed
    Needs-Triage
    on Apr 28, 2021
  6. TravisEz13 commented on Apr 28, 2021

    @TravisEz13
    Member

    remoting working group: #12240

  7. ghost closed this as completedon Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-EnhancementResolution-DuplicateWG-Remoting

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions