Get registry object values

This topic contains 3 replies, has 2 voices, and was last updated by  Clive Richardson 1 month ago.

  • Author
    Posts
  • #89546

    Clive Richardson
    Participant

    I've been trying to extract some registry key values and failing miserably.

    This is as far as I can get:-

    $val = @()
    $Val = Get-ChildItem "hklm:\SOFTWARE\NetApp\" | Where name -eq "HKEY_LOCAL_MACHINE\SOFTWARE\NetApp\HostUtilities"
    
    Name                           Property 
    ----                           -------- 
    HostUtilities                  Version      : 7.0.5208.722   
                                   InstallDir   : C:\Program Files\NetApp\Windows Host Utilities\   
                                   LogDir       : C:\temp\netapp\ 
                                   Multipathing : 1
                                   Protocols    : 3  
    

    I can't figure out how to grab the individual values, like InstallDir. Thanks in advance!

    Clive

  • #89611

    Richard Siddaway
    Moderator

    I don't have any NetApp applications on my machine but this should help

    Look at the PowerShell entries

    PS> Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\PowerShell\3'
    
    
        Hive: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3
    
    
    Name                           Property
    ----                           --------
    0409                           Install : 1
    PowerShellEngine               ApplicationBase         : C:\Windows\System32\WindowsPowerShell\v1.0
                                   ConsoleHostAssemblyName : Microsoft.PowerShell.ConsoleHost, Version=3.0.0.0, Culture=neutral,
                                   PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=msil
                                   ConsoleHostModuleName   : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell.ConsoleHost.dll
                                   PowerShellVersion       : 5.1.16299.15
                                   PSCompatibleVersion     : 1.0, 2.0, 3.0, 4.0, 5.0, 5.1
                                   PSPluginWkrModuleName   : C:\Windows\System32\WindowsPowerShell\v1.0\system.management.automation.dll
                                   RuntimeVersion          : v4.0.30319
    

    Under the PowerShellEngine you have a bunch of entries but if you use
    Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine\'

    You get nothing back. You can use get-ItemProperty

    PS> Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine\' -Name PowerShellVersion
    
    
    PowerShellVersion : 5.1.16299.15
    PSPath            : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine\
    PSParentPath      : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3
    PSChildName       : PowerShellEngine
    PSDrive           : HKLM
    PSProvider        : Microsoft.PowerShell.Core\Registry
    
  • #89635

    Clive Richardson
    Participant

    Thanks Richard. Get-ItemProperty is a solution.
    Basic question following on from this is how to output the string value as opposed the @{...}.

    
    $str = Invoke-command -computer "JUNO" { Get-ItemProperty -Path 'HKLM:\SOFTWARE\NetApp\HostUtilities'  -Name InstallDir } | Select InstallDir
    
    $Str
    #output...
    @{InstallDir=C:\Program Files\NetApp\Windows Host Utilities\}
    

    I've tried $Str.ToString() but that doesn't work.

    • #89638

      Clive Richardson
      Participant

      It's ok, I forgot... use Select -ExpandProperty InstallDir.

      Thanks Richard, I'm done. 🙂

You must be logged in to reply to this topic.