PowerShell: The scope in the different script blocks of «Switch» are different too

Prerequisites

Steps to reproduce

$Private:P = "PP"
$Local:L = "LL"
$Global:G = "GG"
"`$P=$P `$L=$L `$G=$G"
Switch ($AnyValue) {
	{"`$P=$P `$L=$L `$G=$G" | Out-Host; $True} {"`$P=$P `$L=$L `$G=$G"}
}

Expected behavior

$P=PP $L=LL $G=GG
$P=PP $L=LL $G=GG
$P=PP $L=LL $G=GG

Actual behavior

$P=PP $L=LL $G=GG
$P= $L=LL $G=GG
$P=PP $L=LL $G=GG

Error details

No response

Environment data

PSVersion                      7.3.1
PSEdition                      Core
GitCommitId                    7.3.1
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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 22 (8 by maintainers)

Most upvoted comments

Thank you for your moral support.