Installing the Latest Notepad++ with PowerShell

I just needed a place to stash this and my GitHub didn’t seem appropriate. I make no guarantees that this will work and it’s only been tested on one system so far.

# Modern websites require TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

#requires -RunAsAdministrator

# Let's go directly to the website and see what it lists as the current version
$BaseUri = "https://notepad-plus-plus.org"
$BasePage = Invoke-WebRequest -Uri $BaseUri -UseBasicParsing
$ChildPath = $BasePage.Links | Where-Object { $_.outerHTML -like '*Current Version*' } | Select-Object -ExpandProperty href
# Now let's go to the latest version's page and find the installer
$DownloadPageUri = $BaseUri + $ChildPath
$DownloadPage = Invoke-WebRequest -Uri $DownloadPageUri -UseBasicParsing
# Determine bit-ness of O/S and download accordingly
if ( [System.Environment]::Is64BitOperatingSystem ) {
    $DownloadUrl = $DownloadPage.Links | Where-Object { $_.outerHTML -like '*npp.*.Installer.x64.exe"*' } | Select-Object -ExpandProperty href -Unique
} else {
    $DownloadUrl = $DownloadPage.Links | Where-Object { $_.outerHTML -like '*npp.*.Installer.exe"*' } | Select-Object -ExpandProperty href -Unique
}
Write-Host "Downloading the latest Notepad++ to the temp folder"
Invoke-WebRequest -Uri $DownloadUrl -OutFile "$env:TEMP\$( Split-Path -Path $DownloadUrl -Leaf )" | Out-Null
Write-Host "Installing the latest Notepad++"
Start-Process -FilePath "$env:TEMP\$( Split-Path -Path $DownloadUrl -Leaf )" -ArgumentList "/S" -Wait

I added the -Unique flag to the end of the download URL detection as indicated in a below message. (Again, nice catch!)

13 thoughts on “Installing the Latest Notepad++ with PowerShell”

  1. It downloaded the notepad++ installer in an AWS EC2 instance running Windows Server 2019. It didn’t start the installer automatically, but download was good enough for me.

    Reply
    • Thanks Mauro. I wasn’t able to reproduce in my own environment, but that doesn’t mean it’s outside the realm of possibility.

      Reply
  2. i ended up doing this.. it installs the latest one 64 bit
    $LocalTempDir = $env:TEMP
    $href = ((Invoke-WebRequest -Uri ‘https://notepad-plus-plus.org/downloads/’).Links | Where-Object { $_.innerText -match ‘current version’ }).href
    $downloadUrl = ((Invoke-WebRequest “https://notepad-plus-plus.org/$href”).Links | Where-Object { $_.innerHTML -match ‘installer’ -and $_.href -match ‘x64.exe’ }).href
    Invoke-RestMethod $downloadUrl -OutFile “$LocalTempDir/np++.exe”
    start-process -FilePath “$LocalTempDir\np++.exe” -ArgumentList ‘/S’ -Verb runas -Wait

    Reply
  3. And updated version in case you want to update existing NotePad++ installed

    $w64=Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | where-Object DisplayName -like ‘NotePad++*’
    $w32=Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | where-Object DisplayName -like ‘NotePad++*’
    Write-Output “Before::::”
    if ($w64) {
    write-Host $w64.DisplayVersion
    } elseif ($w32) {
    write-Host $w32.DisplayVersion
    } else {
    Write-Output “No Version Found”
    }

    # Modern websites require TLS 1.2
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

    # requires -RunAsAdministrator

    # Let’s go directly to the website and see what it lists as the current version
    $BaseUri = “https://notepad-plus-plus.org”
    $BasePage = Invoke-WebRequest -Uri $BaseUri -UseBasicParsing
    $ChildPath = $BasePage.Links | Where-Object { $_.outerHTML -like ‘*Current Version*’ } | Select-Object -ExpandProperty href
    # Now let’s go to the latest version’s page and find the installer
    $DownloadPageUri = $BaseUri + $ChildPath
    $DownloadPage = Invoke-WebRequest -Uri $DownloadPageUri -UseBasicParsing
    # Determine bit-ness of O/S and download accordingly
    if ( [System.Environment]::Is64BitOperatingSystem ) {
    if (Test-Path (“C:\Program Files\Notepad++”)){
    $DownloadUrl = $DownloadPage.Links | Where-Object { $_.outerHTML -like ‘*npp.*.Installer.x64.exe”*’ } | Select-Object -ExpandProperty href
    }else {
    if (Test-Path (“C:\Program Files (x86)\Notepad++”)){
    $DownloadUrl = $DownloadPage.Links | Where-Object { $_.outerHTML -like ‘*npp.*.Installer.exe”*’ } | Select-Object -ExpandProperty href
    }
    }
    }
    #Fix when it get 2 lines of the same URL
    $DownloadUrl = $DownloadUrl[0]

    If ($DownloadUrl -ne $null){
    Write-Host “Downloading the latest Notepad++ to the temp folder”
    Invoke-WebRequest -Uri $DownloadUrl -OutFile “$env:TEMP\$( Split-Path -Path $DownloadUrl -Leaf )” | Out-Null
    Write-Host “Installing the latest Notepad++”
    Start-Process -FilePath “$env:TEMP\$( Split-Path -Path $DownloadUrl -Leaf )” -ArgumentList “/S” -Wait
    }

    $w64=Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | where-Object DisplayName -like ‘NotePad++*’
    $w32=Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | where-Object DisplayName -like ‘NotePad++*’
    Write-Output “After::::”
    if ($w64) {
    write-Host $w64.DisplayVersion
    } elseif ($w32) {
    write-Host $w32.DisplayVersion
    } else {
    Write-Output “No Version Found”
    }

    Reply
  4. Didn’t work for me:
    Invoke-WebRequest : Cannot convert ‘System.Object[]’ to the type ‘System.Uri’ required by parameter ‘Uri’. Specified method is not
    supported.
    At line:20 char:24
    + Invoke-WebRequest -Uri $DownloadUrl -OutFile “$env:TEMP\$( Split-Path …
    + ~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

    Installing the latest Notepad++
    Start-Process : This command cannot be run due to the error: The system cannot find the file specified.
    At line:22 char:1
    + Start-Process -FilePath “$env:TEMP\$( Split-Path -Path $DownloadUrl – …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
    + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

    Reply
  5. On my end, on a fresh WS2019 install, I had to add the “-Unique” flag on the Select-Object statement at line 15 & 17 to ensure only one line was returned, then it installed like a charm.

    Otherwise:
    PS C:\Users\Administrator\Desktop> $DownloadUrl
    https://github.com/notepad-plus-plus/notepad-plus-plus/releases/download/v8.4.4/npp.8.4.4.Installer.x64.exe
    https://github.com/notepad-plus-plus/notepad-plus-plus/releases/download/v8.4.4/npp.8.4.4.Installer.x64.exe

    Thanks! 🙂

    Reply
    • Nice catch Philippe – This script kind of gets borked whenever they decide to change the web page layouts. That is a solid catch, my man.

      Reply
    • Not any simple way I’ve been able to find. There might be a way buried in the executable for Notepad++, but I haven’t taken the time to truly dig in.

      Reply
  6. # Modern websites require TLS 1.2
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

    # Check if Notepad++ is running and close it if it is
    $notepadProcess = Get-Process -Name “notepad++” -ErrorAction SilentlyContinue
    if ($notepadProcess) {
    Write-Host “Closing Notepad++”
    Stop-Process -Name “notepad++” -Force
    }

    #requires -RunAsAdministrator

    # Let’s go directly to the website and see what it lists as the current version
    $BaseUri = “https://notepad-plus-plus.org”
    $BasePage = Invoke-WebRequest -Uri $BaseUri -UseBasicParsing
    $ChildPath = $BasePage.Links | Where-Object { $_.outerHTML -like ‘*Current Version*’ } | Select-Object -ExpandProperty href
    # Now let’s go to the latest version’s page and find the installer
    $DownloadPageUri = $BaseUri + $ChildPath
    $DownloadPage = Invoke-WebRequest -Uri $DownloadPageUri -UseBasicParsing
    # Determine bit-ness of O/S and download accordingly
    if ( [System.Environment]::Is64BitOperatingSystem ) {
    $DownloadUrl = $DownloadPage.Links | Where-Object { $_.outerHTML -like ‘*npp.*.Installer.x64.exe”*’ } | Select-Object -ExpandProperty href -Unique
    } else {
    $DownloadUrl = $DownloadPage.Links | Where-Object { $_.outerHTML -like ‘*npp.*.Installer.exe”*’ } | Select-Object -ExpandProperty href -Unique
    }
    # Extract version from the download URL
    $Version = $DownloadUrl -replace ‘.*npp.([0-9.]+)\.Installer.*’, ‘$1’
    Write-Host “Downloading Notepad++ version $Version to the temp folder”
    Invoke-WebRequest -Uri $DownloadUrl -OutFile “$env:TEMP\$( Split-Path -Path $DownloadUrl -Leaf )” | Out-Null
    Write-Host “Installing Notepad++ version $Version”
    Start-Process -FilePath “$env:TEMP\$( Split-Path -Path $DownloadUrl -Leaf )” -ArgumentList “/S” -Wait

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.