Use powershell to update / install exe

This topic contains 5 replies, has 3 voices, and was last updated by Profile photo of Tim Pringle Tim Pringle 2 years, 2 months ago.

  • Author
    Posts
  • #19140
    Profile photo of James Chicha
    James Chicha
    Participant

    hello there,

    i want to write a ps script that will auto download exe file from suppliers site
    (e.g. http://www.suppliers.com/file.exe)

    then after the download the scripts will check if existing file on local computer has already same file version with new download – if it is, scripts will not continue to run the exe and end the command

    else – the file.exe will continue install and update the current installed application on local computer – then output reports to c:\file.log

    thanks heaps!

  • #19141
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Well, since we can't just write a whole script for you, what part of that would you like help with? What have you already tried?

    • #19143
      Profile photo of James Chicha
      James Chicha
      Participant

      hi don,

      thanks for quick reply.

      below is what i have done so far and im not sure where to go from here

      ps
      (New-Object System.Net.WebClient).DownloadFile("http://www.suppliers.com/file.exe","C:\support\file.exe")
      & 'C:\support.exe' /q

      (Get-Command "C:\Program Files (x86)\Uni\Bin\Uni.exe").FileVersionInfo.Fileversion

      cheers

  • #19147
    Profile photo of Tim Pringle
    Tim Pringle
    Participant

    Hey James, if i understand this right, the initial exe is like a compressed zip file, which automatically expands to a folder when you run it, before the dialogue prompts for installation begin? Also not sure how you would resume an installation of a program when the process is already running?

    Code wise, for killing the process, your function would consist of something like this :

    $downloadedVersion = (Get-Command "C:\data\Downloads\ProgramExecutable.exe").FileVersionInfo.Fileversion
    $currentVersion = (Get-Command "C:\Program Files (x86)\Microsoft Corporation\Microsoft Script Browser\ProgramExecutable").FileVersionInfo.Fileversion
    
    If ($downloadedVersion -eq $currentVersion)
    {
      Get-Process -Name 'processname' | Stop-Process -Force
        Exit
    }
    
    

    For the auto download you refer to, I guess you will have options of performing the download via a scheduled task, or a new registered event using a timer. A scheduled task has the advantage that you dont need to have an active powershell session open to perform the task.

    I'm not sure if thats what you mean though. Can you be a bit more specific?

    • #19150
      Profile photo of James Chicha
      James Chicha
      Participant

      hello tim –

      thank you for your reply

      there is a program we use in the engineering group that has weekly /monthly updates – the issue is that once installed by the administrator the only way updates can be loaded is by the administrator -the issue we have that in order to get the administrator to make the updates it has to go to our helpdesk etc and becomes a bureaucratic nightmare for an update. So what happens is we continue to run without the updates because it is easier. Most of the updates are bug fixes and software improvements.

      My question is it possible to write a ps scripts and have a secondary level of administrator who is a regular user of the software and can load the updates for designated programs

      the program is running on a windows 2008 box which has our production program running on it and at least we need the script to run once a month to check if any new release updates frmo vendor site (by checking the fileversion info and do comparison to current installed on server) if fileversion is the same then scripts will terminate the program end of story

      but if new file version is available we want the scripts to be able to download the single exe program from suppliers site – then check if any process running and terminate if process running – then install the new software and create an installation.log in C: after ending the scripts

      ps
      (New-Object System.Net.WebClient).DownloadFile("http://www.suppliers.com/file.exe","C:\support\file.exe")
      & 'C:\support.exe' /q

      (Get-Command "C:\Program Files (x86)\Uni\Bin\Uni.exe").FileVersionInfo.Fileversion

  • #19151
    Profile photo of Tim Pringle
    Tim Pringle
    Participant

    Sounds like a company i worked for a year or two ago and their frequent updates to saplogon.ini. But i'll say no more about that one!

    Some form of scheduling is definately the way to go with this. Does your company use SCCM by any chance? My personal preference would be to use this as you can then just update an existing package with the downloaded file. This could be combined with a Task Sequence from which you can run your powershell code.

    To be honest, for what you want to do though, i'd be more inclined to wrap the file in a Windows Installer package, which can handle everything you need for this, including version control. Then either use a distribution tool like sccm, or create a scheduled task which runs in an administrative context on the engineers systems to access the latest msi file on a network share. This also has the advantage that you only need a one time download.

You must be logged in to reply to this topic.