PowerShell: Java 7 install
<Source lang="powershell">
<#
.SYNOPSIS java instal skript .DESCRIPTION
kui arvutis pole java 7 kausta siis tomatakse alla java ja instalitakse see. ajutine kaust mis lootakse kustutatakse kui instal on onestunud. installib java 32bit win 64bit operatsioonisüsteemile.
.AUTHOR
Priit Lilleleht
- >
- tompab alla java
function javaDL { echo "laen alla java" $storageDir = "C:\tempjava" $webclient = New-Object System.Net.WebClient $url = "http://javadl.sun.com/webapps/download/AutoDL?BundleId=63691" $file = "$storageDir\javanew.exe" $webclient.DownloadFile($url,$file)
instaljava }
- installib java ja kirjudab logi faili
Function instaljava { echo "instaling java" $logi = "C:\tempjava\javasetup.log" $command = "cmd.exe /c start /w C:\tempjava\javanew.exe /s /L $logi" $process = [WMICLASS]"\\.\ROOT\CIMV2:win32_process" $process.Create($command)
- ootab kuni CMD aken sulgub
$ErrorActionPreference = "SilentlyContinue" do {} While (get-process cmd | select -Property Responding)
#anab teada kas instal onestus if (!(get-childitem $logi | select-string "error status: 0" | foreach {$_.line})) { echo "java instal ebaonestus proovike uuesti" } else { Remove-Item C:\tempjava -recurse echo "java on instalitud" } }
- loob ajutise kausta kuhu java alla tomatakse
function lookaust { if (!(Test-Path -path C:\tempjava\)) {
New-Item C:\tempjava\ -type directory javaDL }
else {javaDL} }
- kontrolib kas java 7 on arvutis
if (!(Test-Path -Path 'C:\Program Files (x86)\Java\jre7')) { lookaust
} else { "java 7 on juba arvutise instalitud" }