Search code examples
powershellpowershell-3.0

Powershell - Check for updates to script prior to running


I was wondering if anyone knew of a way to have a powershell script check for updates to itself prior to running.

I have a script that I am going to be dispatching out to multiple computers, and don't want to have to redeploy it to each computer each time a change in the script is made. I would like to have it check a certain location to see if there is a newer version of itself (and update itself if needed).

I can't seem to think of a way to do it. Please let me know if anyone can help out. Thanks.


Solution

  • Well, one way maybe to create a simple batch file that runs your actual script and the first line in that batch file may be to check for existence of a ps1 in your update folder. If there is one, it can copy it down first, and then start your powershell script

    Eg. whenever there is an update, you put your 'Mypowershellscript.ps1' script in c:\temp\update\ folder

    and let's assume your script will be running from

    c:\temp\myscriptfolder\
    

    then you can create batch file like this

    if NOT exist C:\temp\update\mypowershelscript.ps1 goto :end
    
    copy /Y c:\temp\update\MyPowerShellScript.ps1 c:\temp\MyScriptFolder\
    
    :END
    
    %systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -nologo -noprofile -file "c:\temp\myscriptfolder\mypowershellscript.ps1"