Skip to content

Modifying AllScope variable in "global" SessionState affects module but not vice versa #6378

@alx9r

Description

@alx9r

This behavior is surprising to me. I'm not sure if it is as intended, as neither the documentation for ScopedItemOptions nor about_Scopes seem to contemplate the behavior of AllScope variables in the context of multiple SessionStates.

Steps to reproduce

$m = New-Module {}
Set-Variable v -Value 'v.1' -Option AllScope

& $m { $v }
& $m { $v = 'v.2'; $v }
$v
& {
    $v = 'v.3'
}
$v
& $m { $v }

Expected behavior

I expected that

either there really is only one $v and the output is

v.1
v.2
v.2
v.3
v.3

or, there are two $v that are really unrelated and the output is

v.1
v.2
v.1
v.3
v.2

Actual behavior

The actual behavior seems to be consistent with two $v that are sort-of related.

v.1
v.2
v.1
v.3
v.3

Environment data

> $PSVersionTable

Name                           Value                                            
----                           -----                                            
PSVersion                      6.0.0                                            
PSEdition                      Core                                             
GitCommitId                    v6.0.0                                           
OS                             Microsoft Windows 6.3.9600                       
Platform                       Win32NT                                          
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                          
PSRemotingProtocolVersion      2.3                                              
SerializationVersion           1.1.0.1                                          
WSManStackVersion              3.0                                              

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions