Solved

Accessing x64 registry to identify installed Microsoft programs

Posted on 2013-01-16
5
608 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 40

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 40

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
This article will help you understand what HashTables are and how to use them in PowerShell.

839 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