Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Blender auto-updater Powershell script. Check the Readme section (after license) for instructions. Use at your own risk.
# MIT License
# Copyright (c) 2019 Keith Boshoff (Wahooney)
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# READ ME
# History
# 20190905 - Fixed download issue related to Blender changing the name of the zip
# Place in a non-root folder (ie. C:\Apps) for best results.
# This requires 7-zip
# The process:
# * Download the latest blender-2.8x zip from the nightly builder site.
# * Close all open blender instances (this is essential)
# * Delete old blender version
# * Unzip new blender version
# change these variables to suit your needs
# 7-ZIP location
$pathTo7Zip = 'C:\Program Files\7-zip'
# current version do check for
$blenderVersion = 'blender-2.8'
# folder to install blender into, in this case C:\blender-2.8
$blenderInstallLocation = 'C:\'
# folder this script will operate in
$blenderWorkingPath = 'C:\Apps\'
# Here be dragons: don't touch these unless you know what you're doing
# establish environment
$env:Path = $env:Path + ';' + $pathTo7Zip
# Let's get a window foregrounder going
Add-Type @"
using System; using System.Runtime.InteropServices;
public class SFW { [DllImport("user32.dll")][return: MarshalAs(UnmanagedType.Bool)]public static extern bool SetForegroundWindow(IntPtr hWnd); }
"@
$blenderZip = $blenderVersion + '.zip'
$blenderZipFolderPath = $blenderVersion + "*"
$blenderInstallPath = $blenderInstallLocation + $blenderVersion
$blenderZipPath = $blenderWorkingPath + $blenderZip
$blenderSearchString = '*' + $blenderVersion + '*-*-win*64.zip*'
# set working folder
Set-Location -Path C:\Apps
# get blender download page
$blender = Invoke-WebRequest -uri https://builder.blender.org/download/
# find win64 2.80 build
$links = $blender.Links | select href | Where-Object { $_ -like $blenderSearchString }
# remove old zip file
if (Test-Path $blenderZip) { Remove-Item -Path $blenderZip }
# download file
Invoke-WebRequest -uri ('https://builder.blender.org' + $links[0].href) -OutFile $blenderZipPath
# kill all running blender instances
$blenderProcess = Get-Process blender -ErrorAction SilentlyContinue
while ($blenderProcess)
{
$bid = $blenderProcess.id
[SFW]::SetForegroundWindow($blenderProcess.MainWindowHandle) > $out
$blenderProcess.CloseMainWindow() > $out
Write-Host '[WAITING] Close all instances of Blender to continue...';
Wait-Process -Id $bid
[SFW]::SetForegroundWindow((Get-Process -Id $pid).MainWindowHandle) > $out
$blenderProcess = Get-Process blender -ErrorAction SilentlyContinue
}
# unzip file
7z x $blenderZipPath $blenderZipFolderPath
# find new folder
$folder = (Get-ChildItem | Where-Object {$_.Name -like 'blender*' -and ($_.Mode -eq 'd-----')} | select Name).Name
# remove old folder
if (Test-Path $blenderInstallPath) { Remove-Item -Path $blenderInstallPath -Force -Recurse }
# sanitize current folder
Rename-Item -Path $folder -NewName $blenderVersion
# move new folder
Move-Item -Path $blenderVersion -Destination $blenderInstallLocation
#wait for input
Write-Host -NoNewLine 'Press any key to continue...';
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.