Solved

Accessing x64 registry to identify installed Microsoft programs

Posted on 2013-01-16
5
605 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
ID: 38785528
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
ID: 38787785
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
ID: 38787881
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
ID: 38787967
You are certainly correct :) Time for more coffee.
0
 

Author Closing Comment

by:berrypetroleum
ID: 38789541
Thanks for the tip!
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

948 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

23 Experts available now in Live!

Get 1:1 Help Now