Chocolatey Bulk install query

Hi all

So question for those of you who use Chocolatey out there on your Windows install.

Does anyone have a powershell script for installing Chocolatey remotely? E.g. One that checks Chocolatey is installed and then installs If it isn’t and can be run unattended.

I’m trying to make new PC setups and such where I work a lot easier especially big bulk rollouts of new PCs. Given our small size we would rarely have the time to setup all the PCs beforehand or setup one and then clone it. Plus I want something easy for people to manage going forward. Chocolatey seems ideal for that.

We could easily run the script via our RMM software which is installed where I can get away with it via GPO so that is usually always there. I could just run the Chocolatey install command on its own but I don’t want to unnecessarily reinstall chocolatey or generate errors for end users hence why I want to be able to check it is installed first.

Sadly whilst I use powershell a lot, my powershellfu is not quite up to snuff when it comes to something like this :sweat_smile:

As always any replies welcome.

Just include the stock chocolatey install in your script, it will detect that it is installed and silently continue.

For installing programs I usually like to do this: @(“7zip”, “audacity”, “chromium”, “classic-shell”) | % { choco install $_ -y}

But it can also be done this way: choco install 7zip audacity chromium classic-shell -y

The first way powershell runs choco for each program, the second let choco install all of them in a single. I like the first one since a program can fail installing without any chance of affecting the install of the rest of them.

8 Likes

Thanks!

I hadn’t thought about installing multiple programs at once but that does make sense and would make things easier if I work out a ‘standard build’ most of our customers need.

So as a test I spun a Windows 10 test VM and ran the following via our RMM Agent:

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1’))
choco install office365business -y -x86

This worked great and installed Office 365 Business. I added the -x86 flag just for fun.

Only thing I can’t workout is it seems to give the same initial output for the first part regardless whether Chocolatey is installed or not:

"Getting latest version of the Chocolatey package for download.
Getting Chocolatey from https://chocolatey.org/api/v2/package/chocolatey/0.10.13.
Extracting C:\Windows\TEMP\chocolatey\chocInstall\chocolatey.zip to C:\Windows\TEMP\chocolatey\chocInstall…
Installing chocolatey on this machine
Creating ChocolateyInstall as an environment variable (targeting ‘Machine’)
Setting ChocolateyInstall to ‘C:\ProgramData\chocolatey’
WARNING: It’s very likely you will need to close and reopen your shell
before you can use choco.
Restricting write permissions to Administrators
We are setting up the Chocolatey package repository.
The packages themselves go to ‘C:\ProgramData\chocolatey\lib’
(i.e. C:\ProgramData\chocolatey\lib\yourPackageName).
A shim file for the command line goes to ‘C:\ProgramData\chocolatey\bin’
and points to an executable in ‘C:\ProgramData\chocolatey\lib\yourPackageName’.

Creating Chocolatey folders if they do not already exist.

WARNING: You can safely ignore errors related to missing log files when
upgrading from a version of Chocolatey less than 0.9.9.
‘Batch file could not be found’ is also safe to ignore.
‘The system cannot find the file specified’ - also safe.
WARNING: Not setting tab completion: Current user is SYSTEM user.
Chocolatey (choco.exe) is now ready.
You can call choco from anywhere, command line or powershell by typing choco.
Run choco /? for a list of functions.
You may need to shut down and restart powershell and/or consoles
first prior to using choco.
Ensuring chocolatey commands are on the path
Ensuring chocolatey.nupkg is in the lib folder
Chocolatey v0.10.13"

I guess since it says “Creating Chocolatey folders if they do not already exist.” it will just skip over if the folders are there but would be nice if the output indicated that.

Outstanding. You should join the L1T PowerShell club.

@Eden, Knight this man.

one thing to mention using chocolately… if software is removed w/o choco. it creates a mess. considering you want to roll it out to your user base

1 Like

my win version of a package manager. im adding auto choco package installer now…

2 Likes

So one hurdle I wasn’t expecting… a rate limiter lol. Chocolatey rate limit downloads from their site and 15 PCs all trying to install Chocolatey rather set it off… blocked the site IP for an hour. Other than that worked fine but only got 7 done before it triggered.

Querying our RMM supplier at the moment if I can set some sort off 5-10 minute delay between starting one PC to the next when it runs a task.

Curious if anyone knows a way in powershell to maybe get around this by making it start at a random time? I was thinking some combination of Start-Sleep and Get-Random but I think Get-Random only does seconds which may not be enough.

Could do something like:

$RandomDelay = Get-Random -Minimum 15 -Maximum 900
Start-Sleep $RandomDelay

1 Like

Thanks, I’ll give that a go next one of these I do! :slight_smile:

Honestly this was good timing, as I’ve been trying to do something very similar, where I use powershell scripts to backup and delete annoying task manager tasks, run a decrapifier, and install a bunch of base programs. Once it’s finish, I’ll share the zip of it

1 Like