Automating Chocolatey with PsExec
-
Chocolatey, the command line driven package manager for Windows, is easily automatable making it much more enterprise ready. One of the easiest and most traditional ways to do this is via the Sysinternals’ tool PsExec which is a free tool which you can download directly from Microsoft or install using Chocolatey.
I won’t go into using PsExec here as that is well documented online on the Sysinternals site. But using it in conjunction with Chocolatey is very straightforward. What we will do is make a basic FOR loop to handle the real work for us. Assuming all of our desktops are named “desktop%” where the % represents a numerical sequence, we could use the following one liner to do updates for us:
FOR %i in (desktop1 desktop2 desktop3) DO PsExec.exe \%i cup all
Obviously you simply put the list of machines on which you want to update all of your packages in a space delimited list inside of the parenthesis. Very simple.
Now to take this to the next level, we should put our list of machines to update into a text file. This makes things much easier. Start my making a text file called host_list.txt and put a number of hostnames into it, one on each line. Once we have this we have a simple way to iterate through an arbitrary number of Windows machines with a single, one line script.
Now we can do an update of all software on every machine like this:
FOR /F “tokens=*” %i in (host_list.txt) DO PsExec.exe \\%i cup all
Or to install new packages:
FOR /F “tokens=*” %i in (host_list.txt) DO PsExec.exe \\%i cinst 7zip
Now you have a super easy means of using command line package management from a central location.
Originally published on 15th March 2014 on scottalanmiller.com
-
damn, I forgot about this post!
-