PowerShell / PowerShell

PowerShell for every system!
https://microsoft.com/PowerShell
MIT License
44.12k stars 7.14k forks source link

Name collision while using Get-ItemProperty(Value) #24003

Open Supremist opened 2 weeks ago

Supremist commented 2 weeks ago

Prerequisites

Steps to reproduce

I experience name collisions with registry values named: PSPath, PSParentPath, PSChildName, PSProvider. PS> Set-ItemProperty -Path Registry::HKCU\Environment -Name PSPath -Value TEST Check with regedit.exe that PSPath value actually created. Than run: PS> Get-ItemProperty -Path Registry::HKCU\Environment -Name PSPath

Expected behavior

PS> Get-ItemPropertyValue -Path Registry::HKCU\Environment -Name PSPath
TEST

Actual behavior

PS> Get-ItemPropertyValue -Path Registry::HKCU\Environment -Name PSPath
Microsoft.PowerShell.Core\Registry::HKCU\Environment

Error details

No response

Environment data

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

mklement0 commented 2 weeks ago

Yes, unfortunately the provider-added properties such as PSPath shadow any item-native properties of the same name (though, fortunately, such name collisions are rare).

Workaround:

(Get-Item Registry::HKCU\Environment).GetValue('PSPath')