Installing Chocolatey Packages Remotely With PowerShell

One “free” solution for deploying Chocolatey packages remotely is PowerShell. Using PowerShell remoting techniques, software can be deployed in parallel on many different machines at once. In this article, I will demonstrate this.

As I have written previously, Chocolatey is breath of fresh air to Windows sysadmins everywhere, as it allows for a universal way to manage and deploy software in the enterprise. As Chocolatey is best used via its CLI (command line interface) with CMD or PowerShell, there are many different methods one can use to remotely deploy software to client workstations and servers. These solutions could be Puppet, Chef and SCCM among many others.

PowerShell Remoting Example

One command that I find myself using very often is Invoke-Command. This cmdlet allows me run remote commands and scripts on many machines at once, which makes it incredibly powerful. The two main parameters I usually use are ComputerName and ScriptBlock. The ComputerName parameter requires an input of the hostname on which you want to run remote code on. It can be one host or multiple. The ScriptBlock parameter is obviously a block of code you want to run.

In this case, I want to get the status of the User Profile Service on every machine in Active Directory:

PowerShell checks if the User Profile Service is running, and if it does, it prints the computers name to the output:

Chocolatey Install

Whether on a local machine or running on a remote PowerShell session, to install a Chocolatey package is the same command, choco install. To install a package without being prompted add the –y argument. This is something I almost always do.

Here, I want to install Firefox on my local machine:

Remotely Install Google Chrome

In this scenario, I need to install Google Chrome on many machines at once. I will first load the computer names into a variable in PowerShell by querying a specific OU in Active Directory (Windows 10). Then, use Invoke-Command with choco install and do some error checking to see if Chocolatey successfully installed Chrome:

Read more at ipswitch.com

Leave a Reply

Your email address will not be published. Required fields are marked *