Skip to content

Commit becab08

Browse files
author
Robin Stolpe
authored
Merge pull request #10 from rstolpe/dev
Dev
2 parents 6d3cc96 + 7939b9e commit becab08

8 files changed

Lines changed: 21 additions & 22 deletions

File tree

.src/private/function/Confirm-RSWinGet.ps1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
[Parameter(Mandatory = $true, HelpMessage = "The headers and API version for the GitHub API")]
3838
[hashtable]$GithubHeaders,
3939
[Parameter(Mandatory = $false, HelpMessage = "Information about the installed version of WinGet")]
40-
[string]$WinGet
40+
$WinGet
4141
)
4242

4343
if ($WinGet -eq "No") {
@@ -57,12 +57,10 @@
5757
[System.Object]$GithubInfoRestData = Invoke-RestMethod -Uri $GitHubUrl -Method Get -Headers $GithubHeaders -TimeoutSec 10 | Select-Object -Property assets, tag_name
5858
}
5959

60-
[string]$latestVersion = $GithubInfoRestData.tag_name.Substring(1)
61-
6260
[System.Object]$GitHubInfo = [PSCustomObject]@{
63-
Tag = $latestVersion
61+
Tag = $($GithubInfoRestData.tag_name.Substring(1))
6462
DownloadUrl = $GithubInfoRestData.assets | where-object { $_.name -like "*.msixbundle" } | Select-Object -ExpandProperty browser_download_url
65-
OutFile = "$env:TEMP\WinGet_$($latestVersion).msixbundle"
63+
OutFile = "$env:TEMP\WinGet_$($GithubInfoRestData.tag_name.Substring(1)).msixbundle"
6664
}
6765
}
6866
catch {
@@ -74,7 +72,10 @@
7472
}
7573

7674
# Checking if the installed version of WinGet are the same as the latest version of WinGet
77-
if ($WinGet -lt $GitHubInfo.Tag) {
75+
[version]$vWinGet = [string]$WinGet
76+
[version]$vGitHub = [string]$GitHubInfo.Tag
77+
78+
if ([Version]$vWinGet -lt [Version]$vGitHub) {
7879
Write-Output "WinGet has a newer version $($GitHubInfo.Tag), downloading and installing it..."
7980
Invoke-WebRequest -UseBasicParsing -Uri $GitHubInfo.DownloadUrl -OutFile $GitHubInfo.OutFile
8081

.src/private/function/Get-RSInstallInfo.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
# Collects everything in pscustomobject to get easier access to the information
5555
[System.Object]$SysInfo = [PSCustomObject]@{
5656
VCLibs = $(Get-AppxPackage -Name "Microsoft.VCLibs.140.00" -AllUsers | Where-Object { $_.Architecture -eq $Arch })
57-
WinGet = $(try { (Get-AppxPackage -AllUsers | Where-Object { $_.name -like "Microsoft.DesktopAppInstaller" }).version } catch { "no" })
57+
WinGet = $(try { (Get-AppxPackage -AllUsers | Where-Object { $_.name -like "Microsoft.DesktopAppInstaller" } | Sort-Object { $_.Version -as [version] } -Descending | Select-Object Version -First 1).version } catch { "no" })
5858
VisualCRedistUrl = $VisualCRedistUrl
5959
$VCLibsUrl = $VCLibsUrl
6060
Arch = $Arch

Help/Confirm-RSWinGet.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ SYNOPSIS
88

99

1010
SYNTAX
11-
Confirm-RSWinGet [-GitHubUrl] <String> [-GithubHeaders] <Hashtable> [[-WinGet] <String>] [<CommonParameters>]
11+
Confirm-RSWinGet [-GitHubUrl] <String> [-GithubHeaders] <Hashtable> [[-WinGet] <Object>] [<CommonParameters>]
1212

1313

1414
DESCRIPTION
@@ -35,7 +35,7 @@ PARAMETERS
3535
Accept pipeline input? false
3636
Accept wildcard characters? false
3737

38-
-WinGet <String>
38+
-WinGet <Object>
3939

4040
Required? false
4141
Position? 3

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ This module will let you update your installed software with WinGet, many of the
88
This module is perfect for people like me that are to lazy to update every singel software all the time, it's much easier to just run a PowerShell Script.
99
I have added the result from PSScriptAnalyzer in [test folder](https://github.com/rstolpe/WinSoftwareUpdate/tree/main/test) I have some ShouldProcess warnings in this module but that's nothing to worry about really.
1010

11-
# Note
12-
This module are only supported with PowerShell 5.1 because of limitation for the Appx module.
13-
1411
## This module can do the following
1512
- Check what platform your currently running and adapt the downloads for that, if your running x86, amd64, arm64.
1613
- Make sure that you have WinGet installed and up to date, if it's not the module will install / update it for you to the latest version.

RSModuleBuilder.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[string]$apiKey = ""
1010
#
1111
# Changes on every build
12-
[string]$Version = "0.0.9"
12+
[string]$Version = "0.1.0"
1313
[string]$PowerShellVersion = "5.1"
1414
[string]$Tags = '"windows", "maintenance", "autoupdate", "autoupdate-script", "psmodule", "update", "winget", "windows10", "windows11"'
1515
[string]$ProcessorArchitecture = ""

WinSoftwareUpdate/WinSoftwareUpdate.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
RootModule = '.\WinSoftwareUpdate.psm1'
3737

3838
# Version number of this module.
39-
ModuleVersion = '0.0.9'
39+
ModuleVersion = '0.1.0'
4040

4141
# Supported PSEditions
4242
# CompatiblePSEditions = @()

WinSoftwareUpdate/WinSoftwareUpdate.psm1

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Function Confirm-RSWinGet {
140140
[Parameter(Mandatory = $true, HelpMessage = "The headers and API version for the GitHub API")]
141141
[hashtable]$GithubHeaders,
142142
[Parameter(Mandatory = $false, HelpMessage = "Information about the installed version of WinGet")]
143-
[string]$WinGet
143+
$WinGet
144144
)
145145

146146
if ($WinGet -eq "No") {
@@ -160,12 +160,10 @@ Function Confirm-RSWinGet {
160160
[System.Object]$GithubInfoRestData = Invoke-RestMethod -Uri $GitHubUrl -Method Get -Headers $GithubHeaders -TimeoutSec 10 | Select-Object -Property assets, tag_name
161161
}
162162

163-
[string]$latestVersion = $GithubInfoRestData.tag_name.Substring(1)
164-
165163
[System.Object]$GitHubInfo = [PSCustomObject]@{
166-
Tag = $latestVersion
164+
Tag = $($GithubInfoRestData.tag_name.Substring(1))
167165
DownloadUrl = $GithubInfoRestData.assets | where-object { $_.name -like "*.msixbundle" } | Select-Object -ExpandProperty browser_download_url
168-
OutFile = "$env:TEMP\WinGet_$($latestVersion).msixbundle"
166+
OutFile = "$env:TEMP\WinGet_$($GithubInfoRestData.tag_name.Substring(1)).msixbundle"
169167
}
170168
}
171169
catch {
@@ -177,7 +175,10 @@ Function Confirm-RSWinGet {
177175
}
178176

179177
# Checking if the installed version of WinGet are the same as the latest version of WinGet
180-
if ($WinGet -lt $GitHubInfo.Tag) {
178+
[version]$vWinGet = [string]$WinGet
179+
[version]$vGitHub = [string]$GitHubInfo.Tag
180+
181+
if ([Version]$vWinGet -lt [Version]$vGitHub) {
181182
Write-Output "WinGet has a newer version $($GitHubInfo.Tag), downloading and installing it..."
182183
Invoke-WebRequest -UseBasicParsing -Uri $GitHubInfo.DownloadUrl -OutFile $GitHubInfo.OutFile
183184

@@ -244,7 +245,7 @@ Function Get-RSInstallInfo {
244245
# Collects everything in pscustomobject to get easier access to the information
245246
[System.Object]$SysInfo = [PSCustomObject]@{
246247
VCLibs = $(Get-AppxPackage -Name "Microsoft.VCLibs.140.00" -AllUsers | Where-Object { $_.Architecture -eq $Arch })
247-
WinGet = $(try { (Get-AppxPackage -AllUsers | Where-Object { $_.name -like "Microsoft.DesktopAppInstaller" }).version } catch { "no" })
248+
WinGet = $(try { (Get-AppxPackage -AllUsers | Where-Object { $_.name -like "Microsoft.DesktopAppInstaller" } | Sort-Object { $_.Version -as [version] } -Descending | Select-Object Version -First 1).version } catch { "no" })
248249
VisualCRedistUrl = $VisualCRedistUrl
249250
$VCLibsUrl = $VCLibsUrl
250251
Arch = $Arch

test/PSScriptAnalyzer_WinSoftwareUpdate.psm1_2023-01-18.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ RuleSuppressionID :
1111
SuggestedCorrections :
1212
IsSuppressed : False
1313

14-
Line : 306
14+
Line : 307
1515
Column : 10
1616
Message : Function 'Start-RSWinGet' has verb that could change system state. Therefore, the function has to support 'ShouldProcess'.
1717
Extent : Start-RSWinGet

0 commit comments

Comments
 (0)