There’s a special place in my heart full of sympathy for those poor souls who are allergic to chocolate. Chocolate is one of those rare delicacies that just about fixes all of life’s problems with just one sweet little treat eaten at the right time, which is any time. And for the record, if you don’t like chocolate/all things chocolatey and you don’t have an allergy, I don’t know if we can be friends.

Thankfully—allergy or not—some wonderful people wrote a little slice of amazing called Chocolatey, and it is quite delicious.

\\\Not vanilla

What is Chocolatey? I didn’t know this inedible yet incredible piece of software existed until a couple of months ago my friend Trey introduced me to this wizard of a wizard. Picture this: you reformat your computer because for some reason you still haven’t let go of Limewire and your computer tested positive for Covid-19. You get out your OS floppies and reformat your ill machine only to have to painfully reinstall all of your software once again. You don’t really remember what you even had but you know without a doubt you can’t live without it. So you frantically scavenge the deep recesses of your brain and barely escape unscathed only to realize a month later that you forgot to install that one app you now desperately need. This process is brutal and could definitely use more chocolate.

Up until this point I used ninite for the most common software, but it has its limitations since it has a finite number of applications to choose from. With Chocolatey, it’s an eternal chocolate river of applications as far as the eye can see but with less pain than that one kid from Willy Wonka and the Chocolate Factory experienced.

\\\Let’s get chocolatey

You could go to the chocolatey website, download the software, manually install it, run some commands and enjoy life…but why would we do that when there’s a Chocolatey module in the PS Gallery utilizing OneGet that we can stuff our faces with?

First things first, we need to install the module from the gallery. Launch PowerShell and install the module:

Install-PackageProvider ChocolateyGet -Force
Now that the module is installed (you do have to run PS with elevated permissions), you can find packages by either going to the Chocolatey website and searching for a package to determine the name, or you can use PowerShell to find packages by name. I think you can figure out how to use the website, but if you want to search in PowerShell, here’s an example of how I would get the packages that contain the word “python” in the name:
Find-Package -ProviderName ChocolateyGet -Name *python*
Once we have the names of all of the packages we want to install, we can add the names to an array and then pass that to the Install-Package cmdlet and let it do the dirty work for us. First, let’s build the array of application names:
Array of Packages
$Packages = @(
'winscp',
'winrar',
'vscode',
'vscode-python',
'vscode-powershell',
'evernote',
'onedrive',
'googlechrome',
'firefox',
'postman',
'javaruntime',
'vlc',
'putty',
'steam',
'origin',
'uplay',
'dswindows',
'discord',
'hwinfo',
'windirstat'
)

\\\Brownies

Before we go fruit loops and get ahead of ourselves, let’s check our one liner first. Failing once is bearable; failing over and over in a loop is depressing, just ask my boy Tom. We don’t want to be depressed. If everything goes according to plan, we should be asked to install the package* with no signs of depression. Here’s what our one liner looks like:

Install-Package -ProviderName ChocolateyGet -Name vscode
* If you see this message:

Install-Package : Unable to find package providers (chocolateyget).
At line:1 char:1
+ Install-Package -ProviderName chocolateyget -Name vscode
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check your ExecutionPolicy settings and make sure it’s set to unrestricted using this code:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted

\\\Looper, Starring Bruce Willis

Cool. Since our one liner worked, let’s make like a snickerdoodle and build our loop! In order to save ourselves from creating a PSCustomObject for additional parameters, let’s leave our list of packages as a simple array and then just create exceptions in our loop for each one that needs additional parameters or switches called.

As an example, I don’t want Visual Studio Code to create a shortcut on the desktop. Desktop icons don’t spark joy in my life so I’ve cut them out completely so I can see that nice shiny Windows Logo for all of its 4 square geometric goodness. If you have other exceptions you can write them in as another elseif statement (after the first if and before the final else). I’ve demonstrated 2 here for simplicity’s sake but you can elseif your heart out.

Also, note that we added -Force to our Install-Package cmdlet. This will skip the confirmation prompts. Yippee.

Putting our concoction altogether, it looks like this:

Chocolate Cake
$Packages = @(
'winscp',
'winrar',
'vscode',
'vscode-python',
'vscode-powershell',
'evernote',
'onedrive',
'googlechrome',
'firefox',
'postman',
'javaruntime',
'vlc',
'putty',
'steam',
'origin',
'uplay',
'dswindows',
'discord',
'hwinfo',
'windirstat'
)
foreach($P in $Packages){
    #In my example, most of these I don't need additional arguments so rather than define a PSCustomObject
    #with an AdditionalArgument column for each, I just wrote the exceptions below in an if/else statement
    if($P -eq 'vscode'{
        Install-Package -ProviderName ChocolateyGet -Name $P -AdditionalArguments '--params "/NoDesktopIcon"' -Force
    }
    else{
        Install-Package -ProviderName ChocolateyGet -Name $P -Force
    }
}
And that’s it buttercup (Reese’s of course). Now we can save this script and easily run it again to install (or update using -RequiredVersion latest) applications with ease. What was once cumbersome and tasteless is now quite delightful to the palate thanks to Chocolatey. Bon appétit!

OTHER POSTS YOU WANT TO READ

Index Scripts for Windows Search

So you just finished writing some code and you go to save your file. You summarize all of the important aspects this section of code contains into a nice, easy-to-read file name that your future self will immediately recognize. Fast forward to the future where you...

Array vs ArrayList (PowerShell)

For some tasks in life, being precise is a necessity. But most of us get away with rounding, paraphrasing, and hitting in the general vicinity most of the time. Depending on your personality, you may be one who strives for perfection and strains on every miniscule...

Spice Up HTML Emails with PowerShell – Part III

So far in this series we've fumbled our way around the kitchen and tried to wing it when sending HTML emails with PowerShell. It was clunky to say the least. We then went through our spice rack and built an HTML template, highlighting the nuances of each spicy element...

Spice up HTML Emails with PowerShell – Part II

In Part I of our scrumptious concoction we put our script into the oven to let it bake. But we forgot to add our secret sauce that's sure to leave our recipients drooling, which is clearly our goal. In this post we'll continue to spice up HTML emails with PowerShell...

Spice Up HTML Emails with PowerShell – Part I

I live in the South, specifically in God's country AKA TEXAS BABAY! There's plenty of amazing things about Texas and definitely some reasons to loathe being from Houston, but it's hard to knock our food. I mean, is there really even a debate between Whataburger vs...
%d bloggers like this: