Various results for object of the same type

by Feb 17, 2012

Hi All.

 

function Get-RegKeys {    
 
    # Variant 1:
    $LMRegKey = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey("SOFTWAREMicrosoft.NETFrameworkv3.0") 
 
    # Variant 2:
    # $LMRegKey = Get-Item -Path "HKLM:SOFTWAREMicrosoft.NETFrameworkv3.0"     
 
    if ($LMRegKey -eq $NULL) {         
        return
    }
 
    $LMRegKey | Get-Member  # Both variants return object of Microsoft.Win32.RegistryKey class
 
    # But next code line return different results (the first variant works incorrectly) !!!
    $LMRegKey | Get-ChildItem | Get-ChildItem    
}

 

Why it happens?

Regards
P.S. Sorry for my English.