Get Java version from PowerShell of remote server Get Java version from PowerShell of remote server powershell powershell

Get Java version from PowerShell of remote server


Honestly, I would just check the version of the file java.exe, something like

$Machines = Get-Content C:\Lists\Servers.txt$Machines | for-each{$java = gci '\\$_\c$\Program Files (x86)\Java\jre7\bin\java.exe'$java.VersionInfo

And you get a VersionInfo object back , something like

 ProductVersion   FileVersion      FileName --------------   -----------      -------- 7.0.510.13       7.0.510.13       \\$_\c$\Program Files (x86)\Java\jre7\bin\java.exe

Or probably $null if path not found (of course you can check for that first with test-path but whatever). Good thing is that you can do real operations with the VersionInfo object if you so choosed, one of the awesome benefits of powershell. And Java sucks.


You can use this one liner for getting the latest java version installed. If u have older versions installed too it only returns the latest:

[system.diagnostics.fileversioninfo]::GetVersionInfo(('C:\Program Files (x86)\Java\'+([regex]::matches((&"java.exe" -version 2>&1)[0].ToString(), '(?<=\").+?(?=\")').value.Insert(0,"jre")) + "\bin\java.exe"))


This should work with no problem

gc "D:\serverlists\serverlist.txt" | foreach {  [system.diagnostics.fileversioninfo]::GetVersionInfo("\\$_\c$\Program Files\Java\jre6\bin\java.exe"); }