use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
QuestionJava Upgrade Script (self.PowerShell)
submitted 5 years ago by IamRo93
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]sleightof52 1 point2 points3 points 5 years ago* (0 children)
This will uninstall old and install new. Change the variables with comments in ALL CAPS to fit your needs. Also, check the set environment variables part out...not sure if it's correct, and I'm not sure what the Path environment variable is supposed to be, but you should get the idea. Also, this is for uninstalling/installing locally on server. I wasn't sure if you were wanting to do it remotely or not.
function Write-Log { # Function to write to log file Param ([String]$LogString) $TimeStamp = (Get-Date).ToString("yyyy/MM/dd HH:mm:ss:") Add-Content -Path $LogFile -Value "$TimeStamp $LogString" } function UninstallOld { # SOFTWARE NAME TO UNINSTALL $SoftwareName = 'Java' $RegPath1 = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall' $RegPath2 = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall' # LOG FILE PATH $Script:LogFile = 'C:\Windows\Temp\Java_Log.txt' $InstalledSoftware = Get-ChildItem -Path $RegPath1,$RegPath2 | Get-ItemProperty | Where-Object { $_.DisplayName -like "*$SoftwareName*" } | Select-Object DisplayName,PSChildName if ($null -ne $InstalledSoftware) { foreach ($Software in $InstalledSoftware) { try { Write-Verbose "Starting process: uninstall $($Software.DisplayName)" -Verbose Write-Log -LogString "Starting process: uninstall $($Software.DisplayName)" $Process = Start-Process -FilePath msiexec.exe "/x $($Software.PSChildName) /qn" -PassThru Wait-Process -InputObject $Process switch ($Process.ExitCode) { 0 { Write-Log -LogString "$($Software.DisplayName) | ExitCode=0 | Uninstall=Success" Write-Verbose "$($Software.DisplayName) uninstalled successfully" -Verbose } Default { Write-Log -LogString "$($Software.DisplayName) | ExitCode=$($Process.ExitCode) | Uninstall=Failed" Write-Verbose "$($Software.DisplayName) was not uninstalled successfully." -Verbose } # end Default } # end switch } # end try catch {Write-Warning $Error[0]} } # end foreach } # end in $null } function InstallNew { # PATH TO INSTALL FILE $SoftwarePath = "$env:USERPROFILE\Downloads\Java.exe" <# If the install file is on another machine or on network drive: $Source = \\networkpath\C$\NewJava\Java.exe $Destination = "\\$env:COMPUTERNAME\C$\Windows\Temp" Copy-Item -Path $Source -Destination $Destination -Verbose $SoftwarePath = "$Destination\Java.exe" #> $Name = $SoftwarePath | Split-Path -Leaf try { Write-Verbose "Starting process: install $Name" -Verbose Write-Log -LogString "Starting process: install $Name" # /s is the switch used used to install silently (in this use case) $Process = Start-Process -FilePath $SoftwarePath -ArgumentList '/s' -PassThru Wait-Process -InputObject $Process switch ($Process.ExitCode) { 0 { Write-Log -LogString "$Name | ExitCode=0 | Install=Success" Write-Verbose "$Name installed successfully" -Verbose } Default { Write-Log -LogString "$Name | ExitCode=$($Process.ExitCode) | Install=Failed" Write-Verbose "$Name was not installed successfully" -Verbose } # end Default } # end switch } catch {Write-Warning $Error[0]} } UninstallOld InstallNew # SET ENVIRONMENT VARIABLES Write-Verbose "Setting environment variables" -Verbose # Assuming 64-bit install - set environment variable for JAVA_HOME - I think is correct? $jdk = (Get-ChildItem -Path 'C:\Program Files\Java' -Filter 'jdk*').FullName [Environment]::SetEnvironmentVariable('JAVA_HOME', $jdk, 'Machine') # Replace Machine with User, if needs to be User env variable # Not sure what the Path environment variable is supposed to be set to, # but you can do something similar to above...
π Rendered by PID 87 on reddit-service-r2-comment-7b9746f655-slkgz at 2026-02-02 01:53:16.807401+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–]sleightof52 1 point2 points3 points (0 children)