Skip to content

Instantly share code, notes, and snippets.

@copernicus365
Created July 19, 2022 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save copernicus365/e3beb726e8269d653249f7a054bcb85a to your computer and use it in GitHub Desktop.
Save copernicus365/e3beb726e8269d653249f7a054bcb85a to your computer and use it in GitHub Desktop.
Powershell script to use choco (chocolately) to install apps from a packages.txt file. Includes dry run ability and print out. Installs choco if needed. Must have a packages.txt file in same directory (see other gist with sample)
## To fix "cannot be loaded because running scripts is disabled on this system" (run: 'get-executionpolicy' returns: Restricted) -->
## set-executionpolicy remotesigned
# Run following to bypass "not digitally signed" issue (fixes per session only)
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
$dryRun = $false;
$packages = 'packages.txt' #'packages-test.txt'
write-host "`n---+++ START powershell script to install packages, using chocolately (`chocolatey.org`) +++---`n"
if($dryRun) {
write-host "... DRY RUN ONLY ..."
}
$chocoIsInstalled = Test-Path -Path "$env:ProgramData\Chocolatey" # Get-Command choco.exe -ErrorAction SilentlyContinue
if ($chocoIsInstalled) {
write-host "`n--> Chocolately is already installed ---`n"
}
else {
write-host "`n--> Chocolately was not installed, let's install it! ---`n"
if(!$dryRun) {
write-host "Just kiddin', not gonna install choco"
}
else {
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
}
}
$array = (gc $packages) -notmatch '^\s*$' -notmatch '^#' | ? {$_.trim() -ne "" }
foreach($item in $array)
{
write-host "`n* --> Next package install: '${item}'`n"
if($dryRun) {
write-host "Just kiddin', not gonna do it"
}
else {
choco install $item -fy
}
}
write-host "`n---+++ FINISH install script +++---`n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment