Home Dashboard Directory Help
Search

Get-Item can return information about local registry values when used with PS Remoting by muffyn


Status: 

Active


1
0
Sign in
to vote
Type: Bug
ID: 830051
Opened: 3/7/2014 5:47:18 PM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

This occurs with PS 3.0 and PS 4.0.

When you use Get-Item to retrieve a registry key (item), the formatting data also gives you data about the contained registry values (item properties). The formatting comes from the file "Registry.format.ps1xml". The relevant portion which displays the info about registry values is here:
$result = (Get-ItemProperty -LiteralPath $_.PSPath |
    Select * -Exclude PSPath,PSParentPath,PSChildName,PSDrive,PsProvider |
    Format-List | Out-String | Sort).Trim()
$result = $result.Substring(0, [Math]::Min($result.Length, 5000) )
if($result.Length -eq 5000) { $result += "..." }
$result

This works fine when querying your local registry, but when using PowerShell Remoting with a command like...
Invoke-Command -computername wkstn1 -scriptblock { Get-Item HKLM:\System\CurrentControlSet\Services\msahci }
...the key returned will be from the remote machine, but the values will be from your local machine.

From my investigation the reason for this is because in the formatting, the value of $_.Path which Get-ItemProperty uses is no different than what it would be if Get-Item were run against the local machine's registry. The formatting code should recognize the deserialized object data returned and adjust its output accordingly, either by querying the remote machine for the appropriate registry values, or falling back to PS 2.0 behavior and not trying to display any information about them at all.

Note that if you are in an interactive remote PS session this problem is not seen.
Details
Sign in to post a comment.
Sign in to post a workaround.