Skip to content

Instantly share code, notes, and snippets.

@jd-apprentice
Created August 2, 2023 14:30
Show Gist options
  • Save jd-apprentice/09622d7e3aba252cc43d93be7a8da7b0 to your computer and use it in GitHub Desktop.
Save jd-apprentice/09622d7e3aba252cc43d93be7a8da7b0 to your computer and use it in GitHub Desktop.
Install software in powershell

Before installing the software, you need to change the execution policy

Set-ExecutionPolicy -Scope CurrentUser unrestricted
Set-ExecutionPolicy -Scope LocalMachine unrestricted

With this changes above we can now execute scripts like this

./our_script.ps1

Here is the code for download a software and install it

## ExampleURL https://github.com/lukehaas/RunJS/releases/download/v2.9.0/RunJS-Setup-2.9.0.exe

$downloadUrl = "DIRECT_URL_TO_DOWNLOAD" 
$fileName = [System.IO.Path]::GetFileName($downloadUrl)
$fileNameWithoutExtension = $fileName -replace '\.exe$'
$destinationPath = Join-Path $env:TEMP "$fileNameWithoutExtension.exe"
Invoke-WebRequest -Uri $downloadUrl -OutFile $destinationPath
Start-Process -FilePath $destinationPath -Wait
Remove-Item $destinationPath

## Once the software is installed, you can remove the execution policy
Set-ExecutionPolicy -Scope CurrentUser restricted
Set-ExecutionPolicy -Scope LocalMachine restricted

I highly recommend using chocolatey for managing software in windows enviroments. Here is their webpage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment