Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alexdiliberto/4f21d90cd40a97abdbbe279c58d3dabc to your computer and use it in GitHub Desktop.
Save alexdiliberto/4f21d90cd40a97abdbbe279c58d3dabc to your computer and use it in GitHub Desktop.
Scripts to automatically update all Chocolatey packages installed on your system

Below you can find two scripts which will update all Chocolatey packages installed on your system. The main script is UpdateChoclatey.ps1, but for convenience I also add UpdateChocolatey.bat which will call the former Powershell script (place it in the same folder as the .ps1 file).

The script asks for elevation if needed.

Example call:

C:\> UpdateChocolatey.bat

========= Updating chocolatey... =========
Updating 7zip...
Chocolatey v0.9.9.6
Upgrading the following packages:
7zip
By upgrading you accept licenses for the packages.
7zip v15.14 is the latest version available based on your source(s).

Chocolatey upgraded 0/1 package(s). 0 package(s) failed.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
Updating 7zip.install...
Chocolatey v0.9.9.6
Upgrading the following packages:
7zip.install
By upgrading you accept licenses for the packages.
7zip.install v15.14 is the latest version available based on your source(s).

...

Press any key to continue...
@echo off
powershell -NoProfile -ExecutionPolicy ByPass -File "%~d0%~p0%~n0.ps1"
$here = Split-Path -parent $MyInvocation.MyCommand.Definition
$script = $MyInvocation.MyCommand.Name
$identity = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object System.Security.Principal.WindowsPrincipal($identity)
if (-not $principal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Warning "Not running with administrative rights. Attempting to elevate..."
$command = "-ExecutionPolicy bypass -File `"$here\$script`""
Start-Process powershell -verb runas -argumentlist $command
Exit
}
Write-Host "`n========= Updating chocolatey... ========="
& choco upgrade -y all
Write-Host "Press any key to continue..."
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment