Software deployment with PowerShell and Chocolatey
In Windows, one of the tasks admins most wish to automate is deploying software. Due to agile software development practices, a new version of any given software can come out much more frequently than it did even a few years ago. This ultimately means that to deploy the new version to your computers, you need to be on top of these releases, making packages out of them and installing them to your servers and workstations. This can be a very painstaking task.
Fortunately, Chocolatey is a great solution for automating these tasks for Windows IT professionals, with either its open-source or business (C4B) versions. In this article, I will be using Chocolatey for Business (C4B) in my demonstrations.
Installing the Chocolatey client
For installing the Chocolatey client from the community repository, we can simply run one line of PowerShell:
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
This downloads and runs a PowerShell script that installs Chocolatey into C:\ProgramData\Chocolatey. Very simple! However, if you are installing in an enterprise environment, you will want to install the client from your own internal NuGet repository. You can do this by internalizing the Chocolatey package, which I will show later in the article. For other methods of installing the Chocolatey client, look here.
Installing a Chocolatey package
Now that we’ve installed our Chocolatey client, let’s actually install a package. One of Chocolatey’s great features is the ability to install from multiple sources. That could be the community repository or an internal repository you create.
Here I will install Notepad++:
choco install notepadplusplus -y
One recently added feature of C4B is the ability to have non-admin end users install software via the Chocolatey GUI. This is a great self-service option for businesses wanting to offload requests for installing software.
Creating a Chocolatey package
With C4B, users have the ability to create packages via command-line interface (CLI) or by a package builder GUI (see below). I much prefer the CLI method because it allows you to create a fully unattended software deployment in five seconds with one command: choco new. In this example, I create a package from a Git installer I downloaded.
PS C:\Example> Get-ChildItem Directory: C:\Example Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 1/29/2018 10:42 AM 39984304 Git-2.16.1-64-bit.exe