Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cjerrington/bc95d40750c04680d814dc42fda2b6c6 to your computer and use it in GitHub Desktop.
Save cjerrington/bc95d40750c04680d814dc42fda2b6c6 to your computer and use it in GitHub Desktop.
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[6].browser_download_url
$nppinstallfile = $npp.assets[6].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...$nppinstallfile)"
#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[4].browser_download_url
$nppinstallfile = $npp.assets[4].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