Solved

Accessing x64 registry to identify installed Microsoft programs

Posted on 2013-01-16
5
603 Views
Last Modified: 2013-01-17
Having some issues with a script accessing x64 machine registries. This script works fine for x86 machines, but does not seem to report all installed Microsoft products  for x64( though it does report some). Does anyone have any ideas on how I can get this script working for both x86 and x64?

$computers = gc "C:\temp\workstations.txt"

$array = @()

foreach($pc in $computers){

    #Define the variable to hold the location of Currently Installed Programs

    $UninstallKey="SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
                  
    #Create an instance of the Registry Object and open the HKLM base key

    $reg=[microsoft.win32.registrykey]::OpenRemoteBaseKey('LocalMachine',$pc) 

    #Drill down into the Uninstall key using the OpenSubKey Method

    $regkey=$reg.OpenSubKey($UninstallKey) 

    #Retrieve an array of string that contain all the subkey names

    $subkeys=$regkey.GetSubKeyNames() 

    #Open each Subkey and use GetValue Method to return the required values for each

    foreach($key in $subkeys){

        $thisKey=$UninstallKey+"\\"+$key 

        $thisSubKey=$reg.OpenSubKey($thisKey) 

        $obj = New-Object PSObject

        $obj | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $pc

        $obj | Add-Member -MemberType NoteProperty -Name "DisplayName" -Value $($thisSubKey.GetValue("DisplayName"))

        $obj | Add-Member -MemberType NoteProperty -Name "DisplayVersion" -Value $($thisSubKey.GetValue("DisplayVersion"))

        $obj | Add-Member -MemberType NoteProperty -Name "InstallLocation" -Value $($thisSubKey.GetValue("InstallLocation"))

        $obj | Add-Member -MemberType NoteProperty -Name "Publisher" -Value $($thisSubKey.GetValue("Publisher"))

        $array += $obj

    } 

}

$array | Where-Object { $_.Publisher -eq "Microsoft Corporation"} | select ComputerName, DisplayName, DisplayVersion, Publisher | ft -auto 

Open in new window

0
Comment
Question by:berrypetroleum
  • 3
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
footech earned 500 total points
Comment Utility
x64 machines also have uninstall info under
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
Depending on what OSes you have, you may be able to get away with a check for 64-bit systems by using
If (Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Computer -ea 0).OSArchitecture -eq '64-bit')
{
  "System is 64-bit"
  #get your info
}
Else
{
  "System is 32-bit"
  #get your info
}

Open in new window


I haven't tried working out all the details, but you may be better off using PowerShell Remoting, and just doing something like
gci hklm:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | get-itemproperty | Where-Object { $_.Publisher -eq "Microsoft Corporation"} | select DisplayName,DisplayVersion,Publisher,InstallLocation | Sort DisplayName

Open in new window

0
 

Author Comment

by:berrypetroleum
Comment Utility
Unfortunately this script will be used in a production environment, so I am staying away from the "WmiObject win32_Product" as it is known to cause some issues.. I saw the explanation from this technet blog as well - relevant link.

I'll investigate the other solution you recommended.
0
 
LVL 39

Expert Comment

by:footech
Comment Utility
I'm no WMI expert, but the code I posted uses the Win32_OperatingSystem class, not the Win32_Product class.
0
 

Author Comment

by:berrypetroleum
Comment Utility
You are certainly correct :) Time for more coffee.
0
 

Author Closing Comment

by:berrypetroleum
Comment Utility
Thanks for the tip!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article shows how a content item can be identified directly or through translation of a navigation type. It then shows how this information can be used to create a menu for further navigation.
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now