-1

How to get latest oracle client installation location in windows using powershell script ?

Dinesh T
  • 27
  • 5

3 Answers3

3

The installation instructions for the Oracle Instant Client suggest that no installer is provided on Windows, so there will be no pertinent information in the registry.

Since the instructions include adding the - self-chosen - installation directory to the PATH environment variable, you can locate the installation directory via one of the executables that come with Oracle Instant Client, e.g., adrci.exe:

PS> Split-Path (Get-Command adrci.exe).Path
C:\oracle\instantclient_19_3

Get-Command locates adcri.exe via the directories listed in the PATH environment variable ($env:PATH in PowerShell), and Split-Path extracts the directory path from the resulting file path.


Optional reading: finding the install location of software installed via an installer, by name or name pattern:

Given the title of the question, readers may come here looking to find the installation directory of software that was installed with an installer, typically Windows Installer (e.g. via an *.msi package), using the software's name or a pattern matching it.

Note: The solution below does not work in PowerShell Core as of v7.1, because the Programs provider for the PackageManagement module isn't available there - I don't know if this provider will ever be made available there.


In Windows PowerShell v5.1, you can use the Get-Package cmdlet with the Programs provider and its -IncludeWindowsInstaller switch, which reports the same set of installed applications shown in Control Panel > Programs > Programs and Features (appwiz.cpl) (which includes both 32-bit and 64-bit applications):

# Example: Find Git's install location:
Get-Package -ProviderName Programs -IncludeWindowsInstaller -Name Git* |
  Select Name, @{ n='InstallLocation'; e={ $_.meta.attributes['InstallLocation'] } }

Note that not every installed program's registry information contains an InstallLocation entry, in which case the .InstallLocation property will contain $null.


Note: The Get-Package approach has major advantages over using
Get-CimInstance Win32_Product (and the virtually equivalent but obsolescent
Get-WmiObject Win32_Product):

  • It also allows you to add the -IncludeSystemComponents switch to report auxiliary installed components not directly shown in Control Panel.

    • Curiously, however, Get-WmiObject Win32_Product reports more results than Get-Package -ProviderName Programs -IncludeWindowsInstaller, whereas if you also pass -IncludeSystemComponents to the latter, it reports more. I don't know what accounts for this discrepancy.
  • Filtering by name or name pattern (wildcard expression) is more convenient, via the -Name parameter.

  • It is much faster.

In fact, the Win32_Product CIM/WMI class should be avoided altogether, because its use can have side effects (emphasis added):

Win32_product Class is not query-optimized. Queries such as “select * from Win32_Product where (name like 'Sniffer%')” require WMI to use the MSI provider to enumerate all of the installed products and then parse the full list sequentially to handle the “where” clause. This process also initiates a consistency check of packages installed, verifying and repairing the install. With an account with only user privileges, as the user account may not have access to quite a few locations, may cause delay in application launch and an event 11708 stating an installation failure.

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • This command "Split-Path (Get-Command adrci.exe).Path " giving the expected result , how to use this command to get the same data from remote machine – Dinesh T Aug 30 '20 at 09:17
0

Use this command :

Get-WmiObject -Class Win32_Product -Filter 'Name like "%Oracle%"' | Select Caption,InstallLocation
Afshin
  • 1,405
  • 10
  • 18
  • Nice, but as an aside: The CIM cmdlets (e.g., `Get-CimInstance`) superseded the WMI cmdlets (e.g., `Get-WmiObject`) in PowerShell v3 (released in September 2012). Therefore, the WMI cmdlets should be avoided, not least because PowerShell [Core] (version 6 and above), where all future effort will go, doesn't even _have_ them anymore. For more information, see [this answer](https://stackoverflow.com/a/54508009/45375). – mklement0 Aug 29 '20 at 18:30
  • Also, it seems that `Win32_Product` only finds _32-bit_ applications and [should be avoided altogether](https://support.microsoft.com/en-us/help/974524/event-log-message-indicates-that-the-windows-installer-reconfigured-al), not only for its poor performance, but because it has side effects (consistency checks and repairs). – mklement0 Aug 29 '20 at 21:09
0

You can give a try for this powershell script :

$OS_Architecture = $env:PROCESSOR_ARCHITECTURE
if($OS_Architecture -eq 'x86') 
{
    $key = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*"
}
else
{
    $key = "HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
}

Get-ItemProperty $Key | ? {$_.DisplayName -like "Oracle" } |
        Select DisplayName, DisplayVersion, Publisher, InstallDate |
            FT –AutoSize
Hackoo
  • 18,337
  • 3
  • 40
  • 70