Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Accessing x64 registry to identify installed Microsoft programs

Posted on 2013-01-16
5
Medium Priority
?
614 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 41

Accepted Solution

by:
footech earned 1500 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 41

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

636 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