Announcement

Collapse
No announcement yet.

Getting the value for a specific registry value

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting the value for a specific registry value

    hi all,

    I need to get the registry value for a software installed on all machines.
    I tired without much luck to try and get the value for hklm\software\myob\Myob pdf manager

    I need the value of the value of

    type :REG_SZ name: Version data:1.5

    I need to check and see if all computers have data:1.5

    so first trying no my machine but with no luck.

    I tried Get-ChildItem
    I tried Get-WmiObject but it seems tha the win32_registry is not responding for me at all

    So I am really not sure where do go - i google it and I tried looking.

    any help will be great.

    Thank you for your time

    Avi

  • #2
    Re: Getting the value for a specific registry value

    I am not the best with powershell, but to get it to do something like this, do you not need a funcation?

    Something Like this
    Code:
    function GetVersionData([string]$Computer, [string]$Pattern) {
      $RemoteConnection = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $Computer)
      $RegPath = "SOFTWARE\MYOB\MYOB PDF Manager”
      $Remotekey = $RemoteConnection.OpenSubKey($RegPath)
      $RemoteKey.GetSubKeyNames() | ForEach {
       $SubKey = $RemoteKey.OpenSubKey($_)
       if($SubKey.GetValue("DisplayName") -match $Pattern) {
        $Object = New-Object PsObject
        $Object | Add-Member NoteProperty Name $SubKey.GetValue("DisplayName")
        $Object | Add-Member NoteProperty UninstallString $SubKey.GetValue("UninstallString")
        $Object
       }
       $SubKey.Close()
      }
      $RemoteKey.Close()
      $RemoteConnection.Close()
    }
    With this command line to run it.
    GetUninstallString -Computer "Server1" -Pattern "MOYB"

    I just stole this from a script that I made (stole) ages ago. Hope it helps, but I would not expect it to work atm, but it should be roughly correct.

    Wofen
    Good to be back....

    Comment


    • #3
      Re: Getting the value for a specific registry value

      From the ipowershell from sapien...

      C:\PS>get-itemproperty -path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion `
      -name "ProgramFilesDir"

      Description

      -----------

      This command gets the value name and data of the ProgramFilesDir registry entry in the CurrentVersion registry subkey. The command uses the Path parameter to specify the subkey and the Name parameter to specify the value name of the entry.
      Marcel
      Technical Consultant
      Netherlands
      http://www.phetios.com
      http://blog.nessus.nl

      MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
      "No matter how secure, there is always the human factor."

      "Enjoy life today, tomorrow may never come."
      "If you're going through hell, keep going. ~Winston Churchill"

      Comment


      • #4
        Re: Getting the value for a specific registry value

        Hi Wofen,

        I am new to Powershell so Iam not sure as to the function, but it makes sense.

        thank you for your replay and the time you took, I am going to check it and see how I go

        Avi

        Comment


        • #5
          Re: Getting the value for a specific registry value

          hi Dumber,

          Thank you for your time and the help.
          I tried and yes I am getting the version as well.

          All I have to do now is to find away to run the Get_ItemProperty on all devices on the network.

          Again thank you for your help.

          Comment


          • #6
            Re: Getting the value for a specific registry value

            Code:
            $(get-itemproperty -path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion")."ProgramFilesDir"
            get-itemproperty works only locally.

            Instead use,
            Code:
            $MachineName = 'nameofremotecomputer'
            $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $MachineName)
            $regKey= $reg.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion")
            $regkey.GetValue("ProgramFilesDir")

            Enumerate computers in domain:
            Code:
            $strCategory = "computer"
            
            $objDomain = New-Object System.DirectoryServices.DirectoryEntry
            
            $objSearcher = New-Object System.DirectoryServices.DirectorySearcher
            $objSearcher.SearchRoot = $objDomain
            $objSearcher.Filter = ("(objectCategory=$strCategory)")
            
            $colProplist = "name"
            foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}
            
            $colResults = $objSearcher.FindAll()
            
            foreach ($objResult in $colResults)
                {
                  $objComputer = $objResult.Properties; $objComputer.name
                  $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $objComputer.name)
                  $regKey= $reg.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion")
                  $regkey.GetValue("ProgramFilesDir")
                  Write-Host
                }
            \Rems
            Last edited by Rems; 6th July 2010, 09:02.

            This posting is provided "AS IS" with no warranties, and confers no rights.

            __________________

            ** Remember to give credit where credit's due **
            and leave Reputation Points for meaningful posts

            Comment


            • #7
              Re: Getting the value for a specific registry value

              Thanks for that I am going to test it.
              At the moment I am reading on the microsoft website:
              "Running Windows PowerShell Scripts Against Multiple Computers"


              I really appriciate your help with this and anyone else.

              Thanks
              Avi

              Comment


              • #8
                Re: Getting the value for a specific registry value

                hi wofen,

                Maybe a little simple but I copied the code to powershell nothing happened.
                Can you please help me with that if you have some free time.

                Thanks
                Avi

                Comment


                • #9
                  Re: Getting the value for a specific registry value

                  Use Rems, the code I gave was just a example of one that worked for a slightly different purpose.

                  Also, you will need to know some things, like defining a function and then calling that function. Its rather simple, but getting it all right is big thing in scripting, so here are a few sites that can be of help (please note, these are NOT personally recommened, as I have no used them, and just spent 20 seconds reading them).

                  http://www.powershellpro.com/powersh...tions-filters/ <- How to define call a funcation.
                  http://stam.blogs.com/8bits/2010/05/...owershell.html <-- About Functions.

                  Wofen
                  Good to be back....

                  Comment


                  • #10
                    Re: Getting the value for a specific registry value

                    Hi wofen,

                    Thank you for all your help with this and the information you sent me - I do appriciate it and also wanted you to know that I am about to go and read it.

                    I looked over the internet last night to late and manage to understand the all Get-Object Wmi32
                    Which is amazing.

                    I manage to get some information from my computer and from a remote computer. so learning curve is good. I am not sure how long I can keep this thread open for other to have a look at the help that you and other provided me.
                    again thank you

                    Comment


                    • #11
                      Re: Getting the value for a specific registry value

                      Well its good to hear that you are making progress, and I would much rather help someone to learn then to just teach them some facts.

                      If this thread gets closed, you can always PM me, though I really am not the best for advice on Powershell, while I do know it, i get though with million monkeys approce, write enough code and some of it has to work, but I am always willing to help when I can (and even to try when i cant).

                      Wofen
                      Good to be back....

                      Comment

                      Working...
                      X