r/PowerShell • u/bonesf • Aug 02 '22
I've written a PowerShell script to download and install the Brave Browser without opening Edge
My first go to action on a new Windows machine was to install Firefox, Chrome and now Brave. I felt discomfort having to open Internet Explorer to perform this action. Edge is a great leap forward from IE, however I haven't adopted it as I'm a big fan of Brave.
I've written this script that downloads the Brave Installer via a PowerShell script confirming first that the Brave Browser isn't already installed.
This script will run the installer and confirm that the Brave Browser installed successfully.
3
Aug 03 '22
Here are a few things I would suggest to add to your script:
Check if the software is installed by querying the registry, rather than checking the default file location. (Hint: Win32_Product is evil. Don't use it.)
Validate the file's checksum against what is on Github to ensure that what you are installing is actually what you intended to install. (Hint: Do some reading of "On-Path Attacks")
For your conditionals, I would recommend making them more explicit. There are some situations where if($installed) is going to throw a false negative, whereas if ($null -ne $installed) will always evaluate against the specific intended condition.
Think about additional error handling. (Hint: Read about the benefits of using Try/Catch)
Edit: Download and use PSScriptAnalyzer. You're welcome.
10
u/mprz Aug 02 '22