64 lines
5.3 KiB
PowerShell
64 lines
5.3 KiB
PowerShell
<#
|
|
Author: GabeK
|
|
Date: 4-24-2024
|
|
|
|
.Modified
|
|
|
|
.Synopsis
|
|
Fixes the Java 8 Path environment variable that got changed in version 411
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
Param(
|
|
[Parameter(Mandatory = $false)]
|
|
$App_Name = "Java 8 Update",
|
|
[Parameter(Mandatory = $false)]
|
|
$FileOutput = "C:\Temp\Script Cach\PathEnvironmentVar-$(Get-Date -format yyyy'-'MM'-'dd'_T'HH'-'mm'-'ss).txt"
|
|
|
|
#$FullPath = C:\Program Files (x86)\Common Files\Oracle\Java\java8path
|
|
)
|
|
|
|
#Region Script Start
|
|
If ((Test-Path "C:\Temp\Script Cache") -eq $False) { New-Item -ItemType directory -Path "C:\Temp\Script Cache" }
|
|
Invoke-WebRequest -UseBasicParsing "https://scripts.gabesville.com/Gabesville/Powershell-Scripts/raw/branch/main/Functions%20Scripts/Functions.ps1" -outfile "C:\Temp\Script Cache\Functions.ps1"
|
|
. "C:\Temp\Script Cache\Functions.ps1"
|
|
|
|
#Check to see if program is installed
|
|
$Applist = Get-Software | Sort-Object -Descending
|
|
|
|
If ((Test-Path $EPCacheLocal) -eq $False) { New-Item -ItemType directory -Path $EPCacheLocal }
|
|
|
|
If ($Applist.DisplayName -like "*$App_Name*") {
|
|
$ENV:Path | out-file -filepath $FileOutput
|
|
Write-Host "Backup saved to $FileOutput"
|
|
If ($ENV:Path -like "*\Oracle\Java\java8path*" -and $ENV:Path -notlike "*\Oracle\Java\javapath*" -and $ENV:Path -notlike "*C:\Program Files (x86)\Java\jre1.8.0_*\bin\client*") {
|
|
Write-Host "Java System Environment Variable is correct"
|
|
$ENV:Path
|
|
}
|
|
If ($ENV:Path -like "*\Oracle\Java\javapath*") {
|
|
$FixedPath = $ENV:Path -replace "\\Oracle\\Java\\javapath", "\Oracle\Java\java8path"
|
|
[Environment]::SetEnvironmentVariable("Path", $FixedPath, "Machine")
|
|
Write-Host "Updated Path Environment Variables"
|
|
$ENV:Path
|
|
Write-Host "Please reboot device for changes to take effect!"
|
|
}
|
|
If ($ENV:Path -like "*C:\Program Files (x86)\Java\jre1.8.0_*\bin\client*") {
|
|
# Get it
|
|
$path = [System.Environment]::GetEnvironmentVariable('PATH', 'Machine')
|
|
# Remove unwanted elements
|
|
$path = ($path.Split(';') | Where-Object { $_ -notlike "C:\Program Files (x86)\Java\jre1.8.0_*\bin\client" }) -join ';'
|
|
# Set it
|
|
[System.Environment]::SetEnvironmentVariable('PATH', $path, 'Machine')
|
|
Write-Host "Updated Path Environment Variables"
|
|
$ENV:Path
|
|
Write-Host "Please reboot device for changes to take effect!"
|
|
}
|
|
Else {
|
|
Write-Host "The Java 8 path environment variable is correct. See path variable below:"
|
|
$ENV:Path
|
|
}
|
|
}
|
|
Else {
|
|
Write-Host "The affected Java 8 Runtime Environment is not installed on this machine"
|
|
}
|
|
#Region Script End |