Skip to content

Instantly share code, notes, and snippets.

@dansmith65
Last active December 1, 2020 16:47
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Install latest 64-bit version of Nodepad++ via PowerShell
[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
@dansmith65
Copy link
Author

NOTE: can now get latest version from GitHub instead: https://api.github.com/repos/notepad-plus-plus/notepad-plus-plus/releases/latest

@cjerrington
Copy link

cjerrington commented Dec 1, 2020

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

@dansmith65
Copy link
Author

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