Java Installer

This topic contains 5 replies, has 2 voices, and was last updated by  Chris Romano 3 years, 11 months ago.

  • Author
    Posts
  • #11733

    Chris Romano
    Participant

    Hey guys,

    The script below works fine. It copies the Java.exe to the specified create patch folder on the remote machine. The only thing I cant get to work is the removing it. I have the -force, but it still does not work. I cant figure it out. Please be patient with my coding. I am noob to powershell and I am just learning, so please forgive me for the format/ style. Any helpful tips it much appreciated. Thanks Powershell GURUS.


    $ScriptBlock = {
    param([String]$strComputer, $FileList, $scriptpath)

    function InstallJava {
    param([String]$strComputer, $objFile, $sysArch, $antiarch, $scriptpath)

    write-host ""
    write-host "Java install"
    write-host ""

    $JavaName = [string]$objFile.name
    $JavaExt = $objFile.extension
    $JavaFullName = $objFile.FullName
    $JavaProc = ($JavaName.trimend(".exe"))
    write-host $JavaProc

    $JavaProc = [string]$JavaProc

    If(!(Test-Path \\$StrComputer\c$\patch))
    {
    New-Item -type directory -path \\$StrComputer\c$\patch
    }

    Write-host “Patchs are being copied on $Computers”

    copy-item $JavaFullName \\$strComputer\c$\PATCH\$JavaName -force

    $install = (([WMICLASS]"\\$strComputer\ROOT\CIMV2:win32_process").Create("cmd /c c:\PATCH\$JavaName /s"))

    start-sleep -Seconds 5

    $javatest = get-process -cn $strComputer -name "$JavaProc"

    while ($javatest -ne $null)
    {
    start-sleep -seconds 1
    #write-host "waiting for java install to complete"
    $javatest = get-process -cn $strComputer -name "$JavaProc"

    }

    #Java Auto Updater

    copy-item -force "$scriptpath\wipejavaupdater.bat" "\\$strComputer\c$\\patch\wipejavaupdater.bat" -verbose

    $install = (([WMICLASS]"\\$strComputer\ROOT\CIMV2:win32_process").Create('cmd /c start c:\wipejavaupdater.bat')).processid

    Remove-Item $JavaFullName \\$strComputer\C$\Patch -force #Remove patches from remote system

  • #11735

    Chris Romano
    Participant

    Also guys, I just want to let you know that this is not the entire script. The real script is about 300 lines long. So in one part I have this telling where to pull the computer names from adn the .java exe. AS I said everything works, I just cant get it to remove the the patch folder and ,exes when it is done installing.

    $targetList = get-content C:\targets\computers.txt
    $targetFolder = "C:\targets\patch"

  • #11739

    Dave Wyatt
    Moderator

    So if I understand your post correctly, we can ignore everything except the Remove-Item line, as that's all you need help with?

    If so, try this:

    Remove-Item -Path \\$strComputer\C$\Patch\$JavaName -Force
  • #11742

    Chris Romano
    Participant

    Yes.. You are correct. It should work right?

  • #11749

    Chris Romano
    Participant

    Thanks Dave, for the advice. One question, how would I make it to delete the entire folder? It deletes the jre.exes perfectly. How would I make it remove the entire "patch" folder I established.

    Would it be something like this?
    Remove-Item -Path \\$strComputer\C$\Patch\ -force

  • #11753

    Chris Romano
    Participant

    Disregard Dave, I figured it out. THanks for all the help.

You must be logged in to reply to this topic.