Skip to content

PowerShell 7 not reporting updated environment variable values if setting them in PowerShell 5.1 #15626

@loxia01

Description

@loxia01

Steps to reproduce

Set a new value for an environment variable (have tested with TEMP/TMP) in PowerShell 5.1 using the SetEnvironmentVariable method. Then, in PowerShell 7, issue a command to get the value of the environment variable, either using the GetEnvironmentVariable method or Get-ItemProperty for the registry value, in this case: Get-ItemProperty Registry::HKCU\Environment.

Expected behavior

PowerShell 7 reporting the correct updated value for the environment variable or the registry entry.


Actual behavior

PowerShell 7 will report the old NOT updated value. This behavior is persistent across reboots. However, if referencing the environment variable using the $env: notation, the correct value is used.


Environment data

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19043
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions