Using a simple powershell script we can update any Java version on local multiple remote computer, let’s discuss how to write the powershell code.
If you are a System Administrator and working for a large enterprise company then you must have encountered a situation to install Java on multiple remote computers to maintain the software’s as per industry standards and compliance, we must upgrade newer version of JAVA whenever it is out, in this article we explain how java can be installed.
Java update using a batch file
Before we begin, you need to make sure old version of java is removed on the computers before you install the newer version of JAVA, here is the link available for uninstalling Java.
We need to create a batch file to install the Java, here is the batch file code.
@echo off
:Installing Java on multiple remote compuers using powershell script
cd C:\temp\
start /w jre-8u251-windows-x64.exe /s /l C:\temp\setup.log
exit
Just copy the above code in a notepad file and save it as InstallJava.bat file in any location, we need to copy this file along with Java package or software on the remote computers where you want to install it, see the screenshot for the same.
I have saved two file one is above batch file code and the java package in C:\temp on my local computer, you can store two wherever you want.
We need to create another file for storing all the servers or multiple machines list, I named it as Allservers.txt and saved it in my local machine c:\temp\Allservers.txt
#remote machines list
$machines= Get-Content -Path "C:\temp\AllServers.txt"
foreach ($onemachine in $machines)
{
#java uinstall location file and where to copy on the remote system
Copy-Item -Path "\\sourcemachine\c$\temp\*" -Destination "\\$onemachine\c$\temp" -Recurse -force
Invoke-command -ComputerName $onemachine -Scriptblock {C:\temp\InstallJava.bat} -Asjob
}
Java update using powershell script.
1.The above code first copies the batch file and java software to more computers in C:\temp location
2. After it calls the batch file InstallJava.bat on the remote computers, after the successful installation of java it writes log in temp as setup.log file see the screenshot shown below.
Script runs on each computer as a background job and finishes the installation, wait for all jobs to complete, to get the running job status, use the command get-job -state running.
I hope you find this article useful, if you have any questions please let us know.
Thank you for visiting my site, for any scripts in these articles you are testing please make sure you have tested this script in our lower environment before you run in production.
Leave a Reply Cancel reply