Skip to content

Instantly share code, notes, and snippets.

@chrisdpa-tvx
Last active June 1, 2021 18:00
Show Gist options
  • Save chrisdpa-tvx/32f3864976af9ddb645df340f9230786 to your computer and use it in GitHub Desktop.
Save chrisdpa-tvx/32f3864976af9ddb645df340f9230786 to your computer and use it in GitHub Desktop.
Install Java JRE on windows silently using powershell
$URL=(Invoke-WebRequest -UseBasicParsing https://www.java.com/en/download/manual.jsp).Content | %{[regex]::matches($_, '(?:<a title="Download Java software for Windows Online" href=")(.*)(?:">)').Groups[1].Value}
Invoke-WebRequest -UseBasicParsing -OutFile jre8.exe $URL
Start-Process .\jre8.exe '/s REBOOT=0 SPONSORS=0 AUTO_UPDATE=0' -wait
echo $?
@sagar89jadhav
Copy link

Hi ChrisA,

Hope you are doing well. I am running the above script on one of the packer build but it is failed to download the java software. If i just ran
(Invoke-WebRequest -UseBasicParsing https://www.java.com/en/download/manual.jsp).Content | %{[regex]::matches($_, '(?:<a title="Download Java software for Windows Online" href=")(.*)(?:">)').Groups[1].Value} that gives below error;

Cannot index into a null array.
At line:1 char:94
+ ... Content | %{[regex]::matches($_, '(?:<a title="Download Java software ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

I hope this is something to do with java?

Regards,
SagarJ

@warleyvods
Copy link

Don't work :\

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment