Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install latest 64-bit version of Nodepad++ via PowerShell
# This can trigger an IE ESC Warning which causes the script to hang until user intervenes, so only run this code from an interactive shell
# https://github.com/PowerShell/PowerShell/issues/2048
if ([Environment]::UserInteractive -and (-not ([Environment]::GetCommandLineArgs() | ?{ $_ -like '-NonI*' }))) {
$homeUrl = 'https://notepad-plus-plus.org'
$res = Invoke-WebRequest $homeUrl
if ($res.StatusCode -ne 200) {throw ("status code to getDownloadUrl was not 200: "+$res.StatusCode)}
$tempUrl = ($res.Links | Where-Object {$_.innerText -like "Current Version*"})[0].href
if ($tempUrl.StartsWith("/")) { $tempUrl = "$homeUrl$tempUrl" }
$res = Invoke-WebRequest $tempUrl
if ($res.StatusCode -ne 200) {throw ("status code to getDownloadUrl was not 200: "+$res.StatusCode)}
$dlUrl = ($res.Links | Where-Object {($_.innerText -like "*Installer*") -and ($_.href -like "*x64*")})[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
} else {
Write-Output "skipped installation of Nodepad++ because user interaction can be required"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.