Skip to content
This repository was archived by the owner on Feb 28, 2021. It is now read-only.

Commit 6b6e33e

Browse files
authored
Merge pull request #53 from f0nt4/master
Added WindowsServer option to Get-LatestAdobeFlashUpdate
2 parents c4ae6fc + 6bbb17e commit 6b6e33e

File tree

4 files changed

+83
-40
lines changed

4 files changed

+83
-40
lines changed

LatestUpdate/LatestUpdate.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"Windows10" : "https://support.microsoft.com/app/content/api/content/feeds/sap/en-us/6ae59d69-36fc-8e4d-23dd-631d98bf74a9/atom",
3333
"Windows8" : "https://support.microsoft.com/app/content/api/content/feeds/sap/en-us/b905caa1-d413-c90c-bed3-20aead901092/atom",
3434
"Windows7" : "https://support.microsoft.com/app/content/api/content/feeds/sap/en-us/f825ca23-c7d1-aab8-4513-64980e1c3007/atom",
35+
"WindowsServer" : "https://support.microsoft.com/app/content/api/content/feeds/sap/en-us/6ae59d69-36fc-8e4d-23dd-631d98bf74a9/atom",
3536
"NetFramework" : "https://support.microsoft.com/app/content/api/content/feeds/sap/en-us/df2c02f6-9610-d46d-2d76-fa570bd8c86a/atom",
3637
"WindowsDefender" : "https://support.microsoft.com/app/content/api/content/feeds/sap/en-au/5d4715e7-a9c9-378e-3f83-fd410db4ef0a/atom"
3738
},
@@ -53,7 +54,7 @@
5354
"Windows10", "Windows8", "Windows7"
5455
],
5556
"Versions108" : [
56-
"Windows10", "Windows8"
57+
"Windows10", "Windows8", "WindowsServer"
5758
],
5859
"Versions87" : [
5960
"Windows8", "Windows7"
@@ -62,7 +63,7 @@
6263
"Windows10", "WindowsClient", "WindowsServer"
6364
],
6465
"VersionsComplete" : [
65-
"Windows10", "Windows8", "Windows7", "WindowsClient", "WindowsServer", "All"
66+
"Windows10", "Windows8", "Windows7", "WindowsClient", "WindowsServer", "All"
6667
],
6768
"Windows10" : "Windows 10|Windows Server"
6869
},

LatestUpdate/Public/Get-LatestAdobeFlashUpdate.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ Function Get-LatestAdobeFlashUpdate {
7272
}
7373
If ($Previous.IsPresent) { $gufParams.Previous = $True }
7474
$updateList = Get-UpdateAdobeFlash @gufParams
75-
Write-Verbose -Message "$($MyInvocation.MyCommand): update count is: $($updateList.Count)."
75+
Write-Verbose -Message "$($MyInvocation.MyCommand): update count is: $(($updateList | Measure-Object).count)."
7676

7777
If ($Null -ne $updateList) {
78-
Switch ($OperatingSystem) {
78+
Switch -regex ($OperatingSystem) {
7979

8080
"Windows10" {
8181
ForEach ($ver in $Version) {
@@ -113,7 +113,7 @@ Function Get-LatestAdobeFlashUpdate {
113113
}
114114
}
115115

116-
"Windows8" {
116+
"Windows8|WindowsServer" {
117117
If ($PSBoundParameters.ContainsKey('Version')) {
118118
Write-Information -MessageData "INFO: The Version parameter is only valid for Windows10. Ignoring parameter." `
119119
-InformationAction Continue -Tags UserNotify

LatestUpdate/Public/Save-LatestUpdate.ps1

Lines changed: 67 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ Function Save-LatestUpdate {
6969
[Parameter(Mandatory = $False)]
7070
[System.Management.Automation.SwitchParameter] $ForceWebRequest,
7171

72+
[Parameter(Mandatory = $False)]
73+
[validateset('BitsTransfer','WebRequest','WebClient')]
74+
[System.String] $Method = 'BitsTransfer',
75+
7276
[Parameter(Mandatory = $False)]
7377
[ValidateSet('Foreground', 'High', 'Normal', 'Low')]
7478
[System.String] $Priority = "Foreground",
@@ -99,9 +103,46 @@ Function Save-LatestUpdate {
99103
Write-Verbose -Message "File exists: $updateDownloadTarget. Skipping download."
100104
}
101105
Else {
102-
If ($ForceWebRequest -or (Test-PSCore)) {
103-
If ($pscmdlet.ShouldProcess($url, "WebDownload")) {
106+
If ($ForceWebRequest -or (Test-PSCore) -or ($pscmdlet.ShouldProcess($url, "WebDownload"))) {
107+
#Running on PowerShell Core or ForceWebRequest
108+
$Method = 'WebRequest'
109+
}
110+
If ($pscmdlet.ShouldProcess($(Split-Path -Path $url -Leaf), "BitsDownload")) {
111+
$Method = 'BitsTransfer'
112+
}
113+
If ($pscmdlet.ShouldProcess($(Split-Path -Path $url -Leaf), "WebClient")) {
114+
$Method = 'WebClient'
115+
}
104116

117+
Switch ($Method) {
118+
'BitsTransfer' {
119+
#Running on Windows PowerShell
120+
try {
121+
$sbtParams = @{
122+
Source = $url
123+
Destination = $updateDownloadTarget
124+
Priority = $Priority
125+
DisplayName = $update.Note
126+
Description = "Downloading $url"
127+
ErrorAction = $script:resourceStrings.Preferences.ErrorAction
128+
}
129+
If ($PSBoundParameters.ContainsKey('Proxy')) {
130+
# Set priority to Foreground because the proxy will remove the Range protocol header
131+
$sbtParams.Priority = "Foreground"
132+
$sbtParams.ProxyUsage = "Override"
133+
$sbtParams.ProxyList = $Proxy
134+
}
135+
If ($PSBoundParameters.ContainsKey('ProxyCredential')) {
136+
$sbtParams.ProxyCredential = $ProxyCredentials
137+
}
138+
Start-BitsTransfer @sbtParams
139+
}
140+
catch [System.Exception] {
141+
Write-Warning -Message "$($MyInvocation.MyCommand): Exception: check URL is valid: $url."
142+
Throw $_.Exception.Message
143+
}
144+
}
145+
'WebRequest' {
105146
#Running on PowerShell Core or ForceWebRequest
106147
try {
107148
$iwrParams = @{
@@ -131,37 +172,38 @@ Function Save-LatestUpdate {
131172
Throw $_.Exception.Message
132173
}
133174
}
134-
}
135-
Else {
136-
If ($pscmdlet.ShouldProcess($(Split-Path -Path $url -Leaf), "BitsDownload")) {
137-
138-
#Running on Windows PowerShell
175+
'WebClient' {
139176
try {
140-
$sbtParams = @{
141-
Source = $url
142-
Destination = $updateDownloadTarget
143-
Priority = $Priority
144-
DisplayName = $update.Note
145-
Description = "Downloading $url"
146-
ErrorAction = $script:resourceStrings.Preferences.ErrorAction
147-
}
177+
$webClient = New-Object System.Net.WebClient
178+
148179
If ($PSBoundParameters.ContainsKey('Proxy')) {
149-
# Set priority to Foreground because the proxy will remove the Range protocol header
150-
$sbtParams.Priority = "Foreground"
151-
$sbtParams.ProxyUsage = "Override"
152-
$sbtParams.ProxyList = $Proxy
180+
$proxyObj = New-Object System.Net.WebProxy
181+
$proxyObj.Address = $Proxy
182+
183+
If ($PSBoundParameters.ContainsKey('ProxyCredential')) {
184+
$proxyObj.credentials = $ProxyCredential
185+
}
186+
187+
$webClient.Proxy = $proxyObj
153188
}
154-
If ($PSBoundParameters.ContainsKey('ProxyCredential')) {
155-
$sbtParams.ProxyCredential = $ProxyCredentials
156-
}
157-
Start-BitsTransfer @sbtParams
189+
190+
$webClient.DownloadFile($url, $updateDownloadTarget)
191+
}
192+
catch [System.Net.Http.HttpRequestException] {
193+
Write-Warning -Message "$($MyInvocation.MyCommand): HttpRequestException: Check URL is valid: $url."
194+
Write-Warning -Message ([string]::Format("Error : {0}", $_.Exception.Message))
195+
}
196+
catch [System.Net.WebException] {
197+
Write-Warning -Message "$($MyInvocation.MyCommand): WebException."
198+
Write-Warning -Message ([string]::Format("Error : {0}", $_.Exception.Message))
158199
}
159200
catch [System.Exception] {
160-
Write-Warning -Message "$($MyInvocation.MyCommand): Exception: check URL is valid: $url."
201+
Write-Warning -Message "$($MyInvocation.MyCommand): Failed to download: $url."
161202
Throw $_.Exception.Message
162203
}
163204
}
164205
}
206+
165207
If (Test-Path -Path $updateDownloadTarget) {
166208
$outputObject = [PSCustomObject] @{
167209
KB = $update.KB
@@ -177,4 +219,4 @@ Function Save-LatestUpdate {
177219
}
178220
}
179221
}
180-
}
222+
}

tests/PublicFunctions.Tests.ps1

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ InModuleScope LatestUpdate {
4242

4343
Context "Validate list of Cumulative updates for Windows 10 $Version" {
4444
It "Returns an array of 1 or more updates" {
45-
$Output.Count | Should -BeGreaterThan 0
45+
($Output | Measure-Object).Count | Should -BeGreaterThan 0
4646
}
4747
It "Returns the expected output" {
4848
$Output | Should -BeOfType ((Get-Command Get-LatestCumulativeUpdate).OutputType.Type.Name)
@@ -80,7 +80,7 @@ InModuleScope LatestUpdate {
8080

8181
Context "Validate list of previous Cumulative updates for Windows 10 $Version" {
8282
It "Returns an array of 1 or more updates" {
83-
$Output.Count | Should -BeGreaterThan 0
83+
($Output | Measure-Object).Count | Should -BeGreaterThan 0
8484
}
8585
ForEach ($Update in $Output) {
8686
It "Returns an array with expected property types: [$($Update.Version), $($Update.Architecture)]" {
@@ -105,7 +105,7 @@ InModuleScope LatestUpdate {
105105

106106
Context "Validate list of Servicing Stack updates for Windows 10 $Version" {
107107
It "Returns an array of 1 or more updates" {
108-
$Output.Count | Should -BeGreaterThan 0
108+
($Output | Measure-Object).Count | Should -BeGreaterThan 0
109109
}
110110
It "Returns the expected output" {
111111
$Output | Should -BeOfType ((Get-Command Get-LatestServicingStack).OutputType.Type.Name)
@@ -142,7 +142,7 @@ InModuleScope LatestUpdate {
142142

143143
Context "Validate list of previous Servicing Stack updates for Windows 10 $Version" {
144144
It "Returns an array of 1 or more updates" {
145-
$Output.Count | Should -BeGreaterThan 0
145+
($Output | Measure-Object).Count | Should -BeGreaterThan 0
146146
}
147147
ForEach ($Update in $Output) {
148148
It "Returns an array with expected property types: [$($Update.Version), $($Update.Architecture)]" {
@@ -167,7 +167,7 @@ InModuleScope LatestUpdate {
167167

168168
Context "Validate list of .NET Framework updates for $Version" {
169169
It "Returns an array of 1 or more updates" {
170-
$Output.Count | Should -BeGreaterThan 0
170+
($Output | Measure-Object).Count | Should -BeGreaterThan 0
171171
}
172172
It "Returns the expected output" {
173173
$Output | Should -BeOfType ((Get-Command Get-LatestNetFrameworkUpdate).OutputType.Type.Name)
@@ -204,7 +204,7 @@ InModuleScope LatestUpdate {
204204

205205
Context "Validate list of Monthly Rollup updates for $Version" {
206206
It "Returns an array of 1 or more updates" {
207-
$Output.Count | Should -BeGreaterThan 0
207+
($Output | Measure-Object).Count | Should -BeGreaterThan 0
208208
}
209209
It "Returns the expected output" {
210210
$Output | Should -BeOfType ((Get-Command Get-LatestMonthlyRollup).OutputType.Type.Name)
@@ -241,7 +241,7 @@ InModuleScope LatestUpdate {
241241

242242
Context "Validate list of Monthly Rollup updates for $Version" {
243243
It "Returns an array of 1 or more updates" {
244-
$Output.Count | Should -BeGreaterThan 0
244+
($Output | Measure-Object).Count | Should -BeGreaterThan 0
245245
}
246246
ForEach ($Update in $Output) {
247247
It "Returns an array with expected property types: [$($Update.Version), $($Update.Architecture)]" {
@@ -266,7 +266,7 @@ InModuleScope LatestUpdate {
266266

267267
Context "Validate list of Adobe Flash Player updates for Windows 10 $Version" {
268268
It "Returns an array of 1 or more updates" {
269-
$Output.Count | Should -BeGreaterThan 0
269+
($Output | Measure-Object).Count | Should -BeGreaterThan 0
270270
}
271271
It "Returns the expected output" {
272272
$Output | Should -BeOfType ((Get-Command Get-LatestAdobeFlashUpdate).OutputType.Type.Name)
@@ -298,7 +298,7 @@ InModuleScope LatestUpdate {
298298
$Output = Get-LatestAdobeFlashUpdate -OperatingSystem Windows8
299299

300300
It "Returns an array of 1 or more updates" {
301-
$Output.Count | Should -BeGreaterThan 0
301+
($Output | Measure-Object).Count | Should -BeGreaterThan 0
302302
}
303303
It "Returns the expected output" {
304304
$Output | Should -BeOfType ((Get-Command Get-LatestAdobeFlashUpdate).OutputType.Type.Name)
@@ -334,7 +334,7 @@ InModuleScope LatestUpdate {
334334

335335
Context "Validate list of Adobe Flash Player updates for Windows 10 $Version" {
336336
It "Returns an array of 1 or more updates" {
337-
$Output.Count | Should -BeGreaterThan 0
337+
($Output | Measure-Object).Count | Should -BeGreaterThan 0
338338
}
339339
ForEach ($Update in $Output) {
340340
It "Returns an array with expected property types: [$($Update.Version), $($Update.Architecture)]" {

0 commit comments

Comments
 (0)