Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Accessing x64 registry to identify installed Microsoft programs

Posted on 2013-01-16
5
Medium Priority
?
616 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 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
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…
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 anti-spam), the admin…

810 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