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
Find-Package -ProviderName ChocolateyGet -Name *python*
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
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
}
}
Very well worded!