Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install latest version of Nodepad++ via PowerShell
#Requires Version 3
# Set TLS support for Powershell and parse the JSON request
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$npp = Invoke-WebRequest -UseBasicParsing 'https://api.github.com/repos/notepad-plus-plus/notepad-plus-plus/releases/latest' | ConvertFrom-Json
# Get Hashes for Checksums
Invoke-WebRequest -UseBasicParsing $npp.assets[0].browser_download_url -OutFile $npp.assets[0].name
# Get the download URL from the JSON object per 32/64 bit
if([Environment]::Is64BitOperatingSystem){
Write-Host "Getting install for your 64bit OS"
$dlUrl = $npp.assets[4].browser_download_url
$nppinstallfile = $npp.assets[4].name
# Get hash from checksum file
$hash64bit = Get-Content $npp.assets[0].name | Select-String $nppinstallfile
$hash64bit = $hash64bit -split '\s+'
# $hash64bit[0] is the piece we need
# Start the download and save the file to the $nppinstallfile
Invoke-WebRequest -UseBasicParsing $dlUrl -OutFile $nppinstallfile
# Get hash of the downloaded file
$downloaded = Get-FileHash -Algorithm SHA256 -Path $nppinstallfile
# Check to see if the hashes match
if($hash64bit[0] -match $downloaded.Hash){
# Silently install NotepadPlusPlus then remove the downloaded item
Write-Host "Silently Installing $($npp.name)... Please wait..."
Start-Process -FilePath $nppinstallfile -Args "/S" -Verb RunAs -Wait
Remove-Item $nppinstallfile
Remove-Item $npp.assets[0].name
}else{
Write-Error "Hashes do not match, try again..."
Write-Host $hash64bit[0]
write-host $downloaded.Hash
# Clean up files
Remove-Item $nppinstallfile
Remove-Item $npp.assets[0].name
}
}else{
Write-Host "Getting install for your 32bit OS"
$dlUrl = $npp.assets[2].browser_download_url
$nppinstallfile = $npp.assets[2].name
# Get hash from checksum file
$hash32bit = Get-Content $npp.assets[0].name | Select-String $nppinstallfile
$hash32bit = $hash32bit -split '\s+'
# $hash32bit[0] is the piece we need
# Start the download and save the file to the nppinstallfile
Invoke-WebRequest -UseBasicParsing $dlUrl -OutFile $nppinstallfile
# Get hash of the downloaded file
$downloaded = Get-FileHash -Algorithm SHA256 -Path $nppinstallfile
# Check to see if the hashes match
if($hash32bit[0] -match $downloaded.Hash){
# Silently install NotepadPlusPlus then remove the downloaded item
Write-Host "Silently Installing $($npp.name)... Please wait..."
Start-Process -FilePath $nppinstallfile -Args "/S" -Verb RunAs -Wait
Remove-Item $nppinstallfile
Remove-Item $npp.assets[0].name
}else{
Write-Error "Hashes do not match, try again..."
Write-Host $hash32bit[0]
write-host $downloaded.Hash
# Clean up files
Remove-Item $nppinstallfile
Remove-Item $npp.assets[0].name
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment