-
Notifications
You must be signed in to change notification settings - Fork 0
/
javajdk_checks.ps1
90 lines (89 loc) · 3.07 KB
/
javajdk_checks.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
###########################################
# Java JDK Version Checks
# Authored by Kevin Beattie
# Purpose: Outputs to STDOUT the Version of Java JSK installed, if found
Function Test-RegistryKey {
param(
[Parameter(Mandatory=$true)]
[string]$key
)
process {
if (Test-Path "$Path") {
return $true
} else {
return $false
}
}
} #end function Test-RegistryKey
Function Get-RegistryKeyPropertiesAndValues
{
Param(
[Parameter(Mandatory=$true)]
[string]$path,
[Parameter(Mandatory=$true)]
[string]$key,
[Parameter(Mandatory=$true)]
[string]$value
)
# Test if the Registry Key Exists
Write-Host "Processing: $path"
if(Test-RegistryKey $path){
### Get Sub-Keys
$AllJDKVers = Get-ChildItem -path $Path -Name
ForEach($SubKey in $AlLJDKVers){
Write-Host "Processing: $Path\$SubKey"
$SubKeys = (Get-ItemProperty -Path $Path"\"$SubKey)
}
return $SubKeys
} else {
Write-Host "Key `"$path`" does not exist."
return $false
}
} #end function Get-RegistryKeyPropertiesAndValues
Write-Host "====== PowerShell Version:" $PSVersionTable.PSVersion "======"
$regKeyName = "Java Development Kit"
$regKeyPath64 = "HKLM:SOFTWARE\Wow6432Node\JavaSoft\$regKeyName"
$regKeyPath32 = "HKLM:SOFTWARE\JavaSoft\$regKeyName"
$regValueVersion = "CurrentVersion"
$regValueJavaHome = "JavaHome"
$JDK64 = Get-RegistryKeyPropertiesAndValues -path $regKeyPath64 -key $regKeyName -value $regValueVersion
$JDK32 = Get-RegistryKeyPropertiesAndValues -path $regKeyPath32 -key $regKeyName -value $regValueVersion
$JDKInstalled = $ENV:windir+"\temp\JDK_Detected.log"
$JDKMissing = $ENV:windir+"\temp\JDK_NOT_Detected.log"
if(($JDK64) -Or ($JDK32)){
$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
$OutputFileLocation = $JDKInstalled
Start-Transcript -path $OutputFileLocation -append
if($JDK64){
$Args="-version"
$JavaEXE=($JDK64).JavaHome+"\bin\javac.exe"
$JavaVER= & cmd /c `"`"$JavaEXE`" $Args 2>&1`"
Write-Host "====== Java Results ======"
Write-Host "JavaJDK-64 File: $JavaEXE"
Write-Host "JavaC Version: $JavaVER"
if(Test-Path Env:JAVA_HOME){Write-Host "JAVA_HOME ENV: $ENV:JAVA_HOME"}else{Write-Host "JAVA_HOME ENV: (not set)"}
}
if($JDK32){
$Args="-version"
$JavaEXE=($JDK32).JavaHome+"\bin\javac.exe"
$JavaVER= & cmd /c `"`"$JavaEXE`" $Args 2>&1`"
Write-Host "====== Java Results ======"
Write-Host "JavaJDK-32 File: $JavaEXE"
Write-Host "JavaJDK Version: $JavaVER"
if(Test-Path Env:JAVA_HOME){Write-Host "JAVA_HOME ENV: $ENV:JAVA_HOME"}else{Write-Host "JAVA_HOME ENV: (not set)"}
}
Stop-Transcript
}
if(!($JDK64) -and !($JDK32)){
$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
$OutputFileLocation = $JDKMissing
Start-Transcript -path $OutputFileLocation -append
Write-Host "====== Java Results ======" | Tee-Object -file $JDKMissing
Write-Host "JAVA JDK NOT FOUND!" | Tee-Object -file $JDKMissing
Stop-Transcript
}
Start-Sleep -s 10