Install latest 64-bit version of Nodepad++ via PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
$homeUrl = 'https://notepad-plus-plus.org' | |
$res = Invoke-WebRequest -UseBasicParsing $homeUrl | |
if ($res.StatusCode -ne 200) {throw ("status code to getDownloadUrl was not 200: "+$res.StatusCode)} | |
$tempUrl = ($res.Links | Where-Object {$_.outerHTML -like "*Current Version *"})[0].href | |
if ($tempUrl.StartsWith("/")) { $tempUrl = "$homeUrl$tempUrl" } | |
$res = Invoke-WebRequest -UseBasicParsing $tempUrl | |
if ($res.StatusCode -ne 200) {throw ("status code to getDownloadUrl was not 200: "+$res.StatusCode)} | |
$dlUrl = ($res.Links | Where-Object {$_.href -like "*x64.exe"})[0].href | |
if ($dlUrl.StartsWith("/")) { $dlUrl = "$homeUrl$dlUrl" } | |
$installerPath = Join-Path $env:TEMP (Split-Path $dlUrl -Leaf) | |
Invoke-WebRequest $dlUrl -OutFile $installerPath | |
Start-Process -FilePath $installerPath -Args "/S" -Verb RunAs -Wait | |
Remove-Item $installerPath |
I have created a update based on the GitHub API for those who need it.
# 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 the download URL from the JSON object
$dlUrl = $npp.assets[2].browser_download_url
# Get the file name
$outfile = $npp.assets[2].name
# Get the current directory and build the installer path
$cwd = (Get-Location).Path
$installerPath = Join-Path $cwd $outfile
Write-Host "Silently Installing $($npp.name)... Please wait..."
# Start the download and save the file to the installerpath
Invoke-WebRequest -UseBasicParsing $dlUrl -OutFile $installerPath
# Silently install NotepadPlusPlus then remove the downloaded item
Start-Process -FilePath $installerPath -Args "/S" -Verb RunAs -Wait
Remove-Item $installerPath
I have created a update based on the GitHub API for those who need it.
Awesome; thanks for sharing. I'll try this one out next time I need it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NOTE: can now get latest version from GitHub instead: https://api.github.com/repos/notepad-plus-plus/notepad-plus-plus/releases/latest