member 01
asked on
check java version using powershell
Hi,
I want to check java version in window server 2012 r2 . please let me know the process. Many scripts available in internet are not working though.
I want to check java version in window server 2012 r2 . please let me know the process. Many scripts available in internet are not working though.
Try java --version at command line
ASKER
only powershell is required
$key = 'HKLM\SOFTWARE\JavaSoft\Java Runtime Environment' (Get-ItemProperty -Path $key -Name CurrentVersion).CurrentVersion
This should work:
(Get-WmiObject Win32_Product | Where {$_.Name -match "Java"}).Version
~bp
I tried that but it only hangs on the prompt so I didn't post it
Scratch that, seems my original test finished. It just took a while
Shaun,
The code does not work in PowerGUI IDE:
The code does not work in PowerGUI IDE:
+ $key = 'HKLM\SOFTWARE\JavaSoft\Java Runtime Environment' (Get-ItemPro ...
+ ~
Unexpected token '(' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : UnexpectedToken
ASKER
shaun,
IT does not work
Bill ,
Its giving two outputs, one is correct one is incorrect
IT does not work
Bill ,
Its giving two outputs, one is correct one is incorrect
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Since several versions of Java can be installed at the same time (including the JDK), querying the "CurrentVersion" is not reliable enough.
This will retrieve all Java components, for both x86 and x64:
Bill,
never, ever, use Win32_Product. Want to know why it's so slow? Because it's not just a simple 'read' query - it actively changes the system, because the WMI provider will run a validation (and repair) for each and every msi package found on the system.
Event log message indicates that the Windows Installer reconfigured all installed applications
https://support.microsoft.com/en-us/kb/974524
This will retrieve all Java components, for both x86 and x64:
'', 'Wow6432Node\' |
ForEach-Object {Get-ItemProperty -Path HKLM:\SOFTWARE\$($_)Microsoft\Windows\CurrentVersion\Uninstall\* |
Where-Object {($_.DisplayName -like '*Java *') -and (-not $_.SystemComponent)} |
Select-Object DisplayName, DisplayVersion, @{n='Architecture'; e={If ($_.PSParentPath -like '*Wow6432Node*') {'x86'} Else {'x64'}}}}
Bill,
never, ever, use Win32_Product. Want to know why it's so slow? Because it's not just a simple 'read' query - it actively changes the system, because the WMI provider will run a validation (and repair) for each and every msi package found on the system.
Event log message indicates that the Windows Installer reconfigured all installed applications
https://support.microsoft.com/en-us/kb/974524
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.
@oBdA,
Duly noted, thanks.
(Note: Reference link for additional info on the Win32_Product risks found here.)
Good solution approach.
~bp
Duly noted, thanks.
(Note: Reference link for additional info on the Win32_Product risks found here.)
Good solution approach.
~bp
ASKER
Hi this command is working
Get-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Nod e\JavaSoft \Java Runtime Environment" -Name CurrentVersion
now
I need to check java version and check if 6.29 is installed or not. If any other version are installed than reinstall 6.29.
please suggest
Get-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Nod
now
I need to check java version and check if 6.29 is installed or not. If any other version are installed than reinstall 6.29.
please suggest