r/PowerShell • • 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.

https://github.com/ServerTribe/Attune-Install-Brave-Browser/blob/master/steps/downloadinstallerforbravebrowserforwindows/script.txt

This script will run the installer and confirm that the Brave Browser installed successfully.

https://github.com/ServerTribe/Attune-Install-Brave-Browser/blob/master/steps/runinstallerforbravebrowseronwindows/script.txt

0 Upvotes

21 comments sorted by

10

u/mprz Aug 02 '22
winget install BraveSoftware.BraveBrowser

2

u/BlackV Aug 02 '22

Was gonna add this and

choco install brave

for those that are that way inclined

1

u/bonesf Aug 03 '22

The script works without prerequisite software like choco to be deployed.

1

u/BlackV Aug 03 '22

Yeah that's fair.

one thing I did think of you just check a hard coded path to see if brave in installed, why not check the uninstall registry key to get the path

and you could parameterize this script so people can set locations without editing the script every wtime

EDIT: Spelling I think

1

u/bonesf Aug 03 '22

I didn't want to use the hardcoded path, however I couldn't identify Brave in the uninstall registry. I do that with other installers I've scripted.

# Check if the software is already installed.

$installed = (Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | where { $_.DisplayName -like "$software*" }) -ne $null

EDIT: my backtick's are killing the code block

https://github.com/ServerTribe/Attune-Install-7-Zip/blob/master/steps/runinstallerfor7zonwindows/script.txt

1

u/BlackV Aug 03 '22

that's why I always use 4 spaces/tab for posting

1

u/Creater0822 Sep 10 '23

Also a good reason to use this script is that winget and choco don't install Brave into program files, but instead somewhere in appdata (last I tried)

1

u/BlackV Sep 10 '23

Wait , I just looked at the date here , heh 1year ago

0

u/[deleted] Aug 03 '22

[deleted]

1

u/BlackV Aug 03 '22

wouldn't this

$MyPackages = @(
    'sublimetext'
    'visualstudio2019community'
    'visualstudio2015community'
    'araxismerge'
    'pstools'
    'sysinternals'
    'googlechrome'
    'brave'
    'nmap'
    'advanced-ip-scanner'
    )

work the same (didn't look like you've got any logic tests there for selectively installing)

or

$basic = @(
    'sublimetext'
    'visualstudio2019community'
    'visualstudio2015community'
    'araxismerge'
    )

$Essentials = @(
    'pstools'
    'sysinternals'
    )

$generics = @(
    'googlechrome'
    'brave'
    )

$Network = @(
    'nmap'
    'advanced-ip-scanner'
    )

$MyPackages = $basic, $Essentials, $generics, $Network

0

u/[deleted] Aug 03 '22

[deleted]

1

u/BlackV Aug 03 '22

ha, good times

0

u/[deleted] Aug 03 '22

[deleted]

1

u/BlackV Aug 03 '22

Oh yeah this is nice

1

u/bonesf Aug 03 '22

I initially wrote this script for Windows Server.

Using the Brave silent installer works without first installing WinGet which isn't package with Windows Server OS.

2

u/BlackV Aug 03 '22

ah yeah no winget on server.

1

u/[deleted] Aug 03 '22

I don't know why this is the top answer. OP is showcasing some scripts that he wrote. Just because a solution exists doesn't mean it needs to be thrown in his face as the top comment.

0

u/mprz Aug 03 '22

Probably because the main reason for using powershell is creating solutions for problems. This is reinventing the wheel, so time sunk to solve something that is already solved.

0

u/bonesf Aug 03 '22

The this solution only works in WIN10/11 as it requires other packages to be deployed. The solution I'm creating works without other packages being installed.

0

u/mprz Aug 03 '22

This was nowhere in your original post...

0

u/bonesf Aug 03 '22

That's exactly right the original post doesn't state that additional packages like WinGet and choco were installed.

1

u/mprz Aug 03 '22

Winget is a default in W11

1

u/samuelma Sep 28 '23

installing package managers that may or may not be present is not always a viable solution. Scripts which manage software without prerequisites have many uses. A year later and this has just saved me having to write it myself. Thanks op :)

3

u/[deleted] Aug 03 '22

Here are a few things I would suggest to add to your script:

  1. 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.)

  2. 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")

  3. 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.

  4. Think about additional error handling. (Hint: Read about the benefits of using Try/Catch)

  5. Edit: Download and use PSScriptAnalyzer. You're welcome.