-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-OnlineVerNotepadPlusPlus.ps1
More file actions
163 lines (137 loc) · 6.43 KB
/
Get-OnlineVerNotepadPlusPlus.ps1
File metadata and controls
163 lines (137 loc) · 6.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<#
===========================================================================
Created with: PowerShell ISE (Win10 19042)
Revision: 2022.05.24
Last Modified: 24 May 2022
Created by: Jay Harper (github.com/thecatdidit/powershellusefulscripts)
Organizaiton: Happy Days Are Here Again
Filename: Get-OnlineVerNotepadPlusPlus.ps1
===========================================================================
.CHANGELOG
[2022.05.24]
Updated query source to Github release feed
[2021.07.20]
Fixed a bug with passing of version parameter
Added Notepad++ GUP source for easier pull of needed data
[2021.06.10]
Added '-UseBasicParsing' to web calls re: IE engine decomm
[2021.04.08]
Overhauled source scraping and parsing functions to reflect the vendor's new
site layout
.SYNOPSIS
Queries Notepad++ Website for the current version of
the app and returns the version, date updated, and
download URLs if available.
.DESCRIPTION
This function retrieves the latest data associated with Notepad++.
Utilizes Invoke-WebRequest to query the app's Download Page and
pulls out the Version, Update Date and Download URLs for both
x86 and x64 versions. It then outputs the information as a
PSObject to the Host.
.INPUTS
-Quiet
Use of this parameter will output just the current version of
Google Chrome instead of the entire object. It will always be the
last parameter.
.OUTPUTS
An object containing the following:
Software Name: Name of the software
Software URL: The URL info was sourced from
Online Version: The current version found
Online Date: The date the version was updated
Download URL x86: Download URL for the win32 version
Download URL x64: Download URL for the win64 version
If -Quiet is specified then just the value of 'Online Version'
will be displayed.
.EXAMPLE
PS C:\> Get-OnlineVerNotePadPlusPlus
Software_Name : NotepadPlusPlus
Software_URL : https://notepad-plus-plus.org
Online_Version : 8.4.1
Online_Date : 2022-05-11
Download_URL_x86 : https://github.com/notepad-plus-plus/notepad-plus-plus/releases/download/v8.4.1/npp.8.4.1.Installer.exe
Download_URL_x64 : https://github.com/notepad-plus-plus/notepad-plus-plus/releases/download/v8.4.1/npp.8.4.1.Installer.x64.exe
PS C:\> Get-OnlineVerNotePadPlusPlus -Quiet
8.4.1
.NOTES
Resources/Credits:
https://github.com/itsontheb
https://github.com/aaronparker
#>
function Get-OnlineVerNotepadPlusPlus {
[cmdletbinding()]
param (
[Parameter(Mandatory = $false,
Position = 0)]
[switch]
$Quiet
)
begin {
# Initial Variables
$SoftwareName = 'NotepadPlusPlus'
$URI = 'https://notepad-plus-plus.org/'
$hashtable = [ordered]@{
'Software_Name' = $softwareName
'Software_URL' = 'https://notepad-plus-plus.org'
'Online_Version' = 'UNKNOWN'
'Online_Date' = 'UNKNOWN'
'Download_URL_x86' = 'UNKNOWN'
'Download_URL_x64' = 'UNKNOWN'
}
$swObject = New-Object -TypeName PSObject -Property $hashtable
}
Process {
# Get the Version & Release Date
try {
Write-Verbose -Message "Attempting to pull info from the below URL: `n $URI"
<#Retaining prior query logic for future reference
$uri = 'https://notepad-plus-plus.org/'
$nppURL = (Invoke-WebRequest -Uri $uri -UseBasicParsing)
$nppLink = ($nppURL.Links | Where outerHTML -Match "Current Version")
$nppVersionLink = "https://notepad-plus-plus.org" + $nppLink.href
$nppDate = (Invoke-WebRequest $nppVersionLink -UseBasicParsing)
$nppDate.Content -match "<p>Release Date: (?<content>.*)</p>" | Out-Null
$nppDate = $Matches['content']
$Site = "https://api.github.com/repos/notepad-plus-plus/notepad-plus-plus/releases/latest"
$uri = 'https://notepad-plus-plus.org/update/getDownloadUrl.php'
[xml]$nppVersion = (Invoke-WebRequest -Uri $uri -UseBasicParsing).content
[string]$nppversion = $nppVersion.GUP.Version
#>
$Site = "https://api.github.com/repos/notepad-plus-plus/notepad-plus-plus/releases/latest"
$AppInfo = (Invoke-WebRequest -Uri $Site -UseBasicParsing).Content | ConvertFrom-Json
#Obtain App Version
$AppVersion = $AppInfo.tag_name.Replace("v","")
#Obtain App Release Date
$AppDate = $AppInfo.created_at
$Begin = 0
$End = $AppDate.IndexOf("T")
$AppDate = $AppDate.Substring(0,$End)
$swObject.Online_Date = $AppDate
$swObject.Online_version = $AppVersion
}
catch {
Write-Verbose -Message "Error accessing the below URL: `n $URI"
$message = $("Line {0} : {1}" -f $_.InvocationInfo.ScriptLineNumber, $_.exception.message)
$swObject | Add-Member -MemberType NoteProperty -Name 'ERROR' -Value $message
}
finally {
# Get the Download URLs
if ($swObject.Online_Version -ne 'UNKNOWN') {
$nppDownloadx86 = "https://github.com/notepad-plus-plus/notepad-plus-plus/releases/download/v" + $AppVersion + "/" + "npp." + $AppVersion + ".Installer.exe"
$nppDownloadx64 = "https://github.com/notepad-plus-plus/notepad-plus-plus/releases/download/v" + $AppVersion + "/" + "npp." + $AppVersion + ".Installer.x64.exe"
$swObject.Download_URL_x86 = $nppDownloadx86
$swObject.Download_URL_x64 = $nppDownloadx64
}
}
}
End {
# Output to Host
if ($Quiet) {
Write-Verbose -Message '$Quiet was specified. Returning just the version'
Return $swObject.Online_Version
}
else {
Return $swobject
}
}
} # END Function Get-OnlineVerNotepadPlusPlus