locked
Get-itemproperty of two registry keys RRS feed

  • Question

  • Hello everyone, I am having trouble trying to search for two registry keys in one command.  Not even sure if it is possible the way I am trying, I figured this is a good place to ask.

    I need to search registries of PC's that I have in a file.  What I want to do is bring in the PC names from my file,  then search for two registry keys for each and have the output go to a .csv file.  HELP?

    This is what I have that works to show in the command window, I'd like to search for another key and output all the information to the .csv organized by the computername.  I am open to any suggestions that work.

    get-content C:\scripts\testa.txt | Foreach-object {get-itemproperty -path hklm:\system\CurrentControlSet\Control\ComputerName\ComputerName}

    Second registry key I need to query:

    hklm:\software\misys

     


    Thanks in advance

    Joel

     

     

    Wednesday, October 12, 2011 9:11 PM

Answers

All replies

  • What are you doing with the get-content and foreach there? I don't see the content being used after the pipe. And can you explain more on what you want accomplished with the "two registry keys" and also why you want "one command"
    Wednesday, October 12, 2011 9:59 PM
  • be happy to.....

    I am very new to all of this, so please bear with me if something seems stupid, it probably is.

    What I really want to do is to find all computer names in a list that have the registry key "hklm:\software\misys"  and then output something to indicate whether the hklm:\software\misys exists and match it with the computer name from the original file.

    The way I was trying to do it....because I obviously don't know the proper way, was to pull in a list of computers from testa.txt with the Get-content command and then use foreach to cycle through the list of computer names, return the computername from the registry and whether the hklm:\software\misys exists.


    I obviously have the computer names already, but I need to match up the names with whether the hklm:\software\misys is present.  I'm sure there is a much simpler way to do this.

    I apologize is it's confusing, I'm a little confused on all of this myself

     

    thanks again

    Joel

    Thursday, October 13, 2011 12:20 AM
  • So if I'm not mistaken you have these computernames in a file and you want to query these computers remotely for existence of specific registry keys?

     

    get-content c:\scripts\testa.txt | foreach {
        $registry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $_)
        $registryKey1= $registry.OpenSubKey("SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ComputerName" )
        $registryKey1.GetValueNames()
        $registryKey2= $registry.OpenSubKey("Software\\misys" )
        $registryKey2.GetValueNames()
    }

    you need the remote registry service running for this to work.

     


    • Edited by JorenD Thursday, October 13, 2011 8:25 AM
    Thursday, October 13, 2011 8:24 AM
  • you cant do this in one line (well you could, but its too messy)
     
    Joren has the right idea, you can also download the Remote Registry module
     
    at any rate, id break it up
     

    Justin Rich
    http://jrich523.wordpress.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Thursday, October 13, 2011 1:41 PM
  • Is there a way to use "test-path" against a remote computer? If so, you could do


    $check_registry_A = test-path -path hklm:\software\misys  

    #returns TRUE if it does exist

    $check_registry_A


    Thursday, October 13, 2011 2:35 PM
  • the remote registry module allows you to test remote keys but test-path does
    not.
     
     

    Justin Rich
    http://jrich523.wordpress.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Thursday, October 13, 2011 2:43 PM