The capability to install software remotely on many machines at once is still one of the most magical things a System Administrator can do. Nowadays we take it for granted due to all of the different tools we can use to do this, but it is still one of coolest automated tasks in my opinion.

Today, we will use two tools to accomplish this, PowerShell and Chocolatey. Both automate a lot of tasks on their own, but combining them gives an admin even more power and agility to push out software quickly and easily.

In this example I have three Windows workstations in an Active Directory domain, and I would like to push Firefox to all three at the same time. To do this we will use the PowerShell “Invoke-Command” which allows us to create remote PowerShell sessions to many computers simultaneously. From there we use the choco install command on each workstation which will tell Chocolatey to install Firefox.

First we open PowerShell from our control machine. I will create an array in PowerShell for the hostnames of the workstations I want to install Firefox on.

$workstations = (“computer1″,”computer2″,”computer3”)

Next, lets run the Invoke-Command in PowerShell using the $workstations variable in -ComputerName. You will notice that we pipe choco install firefox -y to Select-String. This is because we want to parse only the result of the installation, specifically the line that includes “Chocolatey installed”. This line will provide if the package was successful or not. Note that you may want to use the -Credential parameter in Invoke-Command if the account you are logged into on your control machine does not have local administrator access to the workstations. Then we use Select-Object to display the installation result for each machine and it’s computer name in PowerShell.

Invoke-Command -ComputerName $workstations -ScriptBlock {choco install firefox -y | Select-String -Pattern “Chocolatey installed” } | select PSComputername,Line

After running Invoke-Command we are greeted with success. Each machine successfully installed Firefox.

PSComputerName Line
————– —-
computer1      Chocolatey installed 1/1 packages. 0 packages failed.
computer2      Chocolatey installed 1/1 packages. 0 packages failed.
computer3      Chocolatey installed 1/1 packages. 0 packages failed.

 

Categories: Technical

Leave a Reply

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

Related Posts

Technical

Restart multiple computers with the PowerShell PCSVDevice module

To restart multiple computers with PowerShell and without relying on functionality of the remote operating system, you can use the PCSVDevice module. The module contains several useful cmdlets for out-of-band management and supports the IPMI Read more…

Technical

Remotely migrate user data with USMT and PowerShell

USMT has been a staple for system administrators for years and has greatly reduced the time to migrate data between computers. USMT has the ability to migrate user files, OS settings, and application settings. It Read more…

Technical

Deploy VMware VMs with PowerCLI and MDT

If you are managing Windows servers, chances are you have a mix of physical and virtual servers in your data center. While VMware provides a method to create VMs from templates to simplify server deployments, Read more…