locked
How to get a registry value RRS feed

  • Question

  • Hi

    I'm strugging to extract a registry value. Can anyone help please. I've Googled for the answer and this is my effort so far:

    #Get Registry Key Value
    $registries=Get-ItemProperty "hklm:\software\AMD\EEU\ApplyBootupProfile"
    
    foreach ($registry in $registries)
    {
        Write-Host $registry.ToString()
    }

    Thanks to anyone who can help me on my way.

    Kind Regards

    Matt

    Wednesday, April 30, 2014 2:24 PM

Answers

  • Get-ItemProperty does not operate remotely unless you configure remoting on your systems.

    However, you can do this easily using the reg command-line tool, provided you have access:


    PS C:\> reg query \\remotecomputer\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion /v ProgramFilesDir
    
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion
        ProgramFilesDir    REG_SZ    C:\Program Files
    


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Bill_Stewart Monday, May 5, 2014 2:34 PM
    • Marked as answer by Bill_Stewart Thursday, June 5, 2014 9:38 PM
    Wednesday, April 30, 2014 3:07 PM

All replies

  • What does "extract" mean? You want to output the value's data to the screen? To a file?

    Keep in mind that Write-Host writes to the screen only and cannot be redirected or written to a file.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, April 30, 2014 2:28 PM
  • Sorry for not being more specific:

    There is a registry value called

    HKLM:\software\microsoft\windows\currentversion\ProgramFilesDir

    On most Pcs, this should have a value of c:\Program Files

    Basically I would just like to output the value of this registry to screen or store it in a variable so then I can compare the value with what it should be.

    Please help!!

    I'm still playing around - this command outputs the full list of registries but I just need ProgramFileDir :-

    Get-Item HKLM:\software\microsoft\windows\currentversion

    Wednesday, April 30, 2014 2:37 PM
  • What's the purpose of this script? You can't change the path to the Program Files directory (see http://support.microsoft.com/kb/933700).

    What is it you really want to know or do? Tell what you want to do, not how you think it needs to be done.


    -- Bill Stewart [Bill_Stewart]

    Wednesday, April 30, 2014 2:43 PM
  • Hi Bill

    I'm not wanting to change this particular registry value - I was just using it as a way to demonstrate the kind of program I need.

    Ultimately, what I need is a script to remote check several registry values (that "should" be set up for the company I work for) to make sure that they exist and that they have the correct value set. Often the registry values are not set properly due to my companies software not being installed correctly in the first place.

    At the moment I only seem able to output a list of registries which is not what I want.

    Thanks if you can help.

    Cheers

    Matt

    Wednesday, April 30, 2014 2:48 PM
  • Here's an example of how to output a single registry value. You want to combine Get-ItemProperty and Select-Object:


    PS C:\> Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion ProgramFilesDir |
    >> Select-Object -ExpandProperty ProgramFilesDir
    C:\Program Files
    


    -- Bill Stewart [Bill_Stewart]

    Wednesday, April 30, 2014 2:55 PM
  • Hi Bill

    Sorry to be a pain but could you send me just the command please - I can't get it to run from PowerShell ISE.

    For example, when I try to run from PowerShell ISE, I get an error saying The Term '>>' is not recognised:-

    Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion ProgramFilesDir |
    >> Select-Object -ExpandProperty ProgramFilesDir

    Thanks again

    Matthew


    • Edited by jmatty2000 Wednesday, April 30, 2014 3:00 PM
    Wednesday, April 30, 2014 3:00 PM
  • Hi Bill

    Its ok, I've removed the >> and it works fine now.

    One more thing, suppose I want to check IP address 10.1.2.3 remotely, is that possible with this command?

    Kind Regards

    Matthew

    Wednesday, April 30, 2014 3:02 PM
  • Get-ItemProperty does not operate remotely unless you configure remoting on your systems.

    However, you can do this easily using the reg command-line tool, provided you have access:


    PS C:\> reg query \\remotecomputer\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion /v ProgramFilesDir
    
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion
        ProgramFilesDir    REG_SZ    C:\Program Files
    


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Bill_Stewart Monday, May 5, 2014 2:34 PM
    • Marked as answer by Bill_Stewart Thursday, June 5, 2014 9:38 PM
    Wednesday, April 30, 2014 3:07 PM
  • One more thing, suppose I want to check IP address 10.1.2.3 remotely, is that possible with this command?

    Look for a -ComputerName property to see if you can easily run cmdlets against remote machines.

    In this case, Get-ItemProperty doesn't have one, so you'll need to use another method.

    Here's a simple way of querying remote registries:

    https://psrr.codeplex.com/


    Don't retire TechNet! - (Don't give up yet - 12,830+ strong and growing)

    Wednesday, April 30, 2014 3:09 PM
  • BOOOOH! I tried the reg query command but get access denied on my customer's server. So potentially this will occur when I try some of my other customers also.

    I will bear https://psrr.codeplex.com/ in mind though.

    In my work, I don't have to remotely check many servers, so I could always transfer the .ps1 script to the server first and run from there.

    Thanks v much - I'll c how I go for now

    Cheers

    Matthew

    Wednesday, April 30, 2014 3:16 PM
  • Remote reg commands will not work unless the remote registry service is running and the firewall is opened.

    WMI remote registry will usually always work but you must be an admin on the remote system.


    ¯\_(ツ)_/¯

    Wednesday, April 30, 2014 4:44 PM