Skip to content

Commit e894bb2

Browse files
author
Robin Stolpe
authored
Merge pull request #12 from rstolpe/dev
Fixed version handling again
2 parents becab08 + 7cd7b1d commit e894bb2

7 files changed

Lines changed: 23 additions & 15 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@
7272
}
7373

7474
# Checking if the installed version of WinGet are the same as the latest version of WinGet
75-
[version]$vWinGet = [string]$WinGet
75+
[version]$vWinGet = [string]$SysInfo.WinGet
7676
[version]$vGitHub = [string]$GitHubInfo.Tag
7777

78-
if ([Version]$vWinGet -lt [Version]$vGitHub) {
78+
if ([Version]$vWinGet -lt [Version]$vGitHub -or $WinGet -like "1.19.3531.0") {
7979
Write-Output "WinGet has a newer version $($GitHubInfo.Tag), downloading and installing it..."
8080
Invoke-WebRequest -UseBasicParsing -Uri $GitHubInfo.DownloadUrl -OutFile $GitHubInfo.OutFile
8181

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
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" } | Sort-Object { $_.Version -as [version] } -Descending | Select-Object Version -First 1).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 { "0.0.0.0" })
5858
VisualCRedistUrl = $VisualCRedistUrl
59-
$VCLibsUrl = $VCLibsUrl
59+
VCLibsUrl = $VCLibsUrl
6060
Arch = $Arch
6161
}
6262

.src/public/function/Update-RSWinSoftware.ps1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,16 @@
6161
#
6262
[string]$VCLibsOutFile = "$env:TEMP\Microsoft.VCLibs.140.00.$($Arch).appx"
6363

64+
# Importing appx with -usewindowspowershell if your using PowerShell 7 or higher
65+
if ($PSVersionTable.PSVersion.Major -ge 7) {
66+
import-module appx -usewindowspowershell
67+
Write-Output "== This messages is expected if you are using PowerShell 7 or higher =="
68+
}
6469

6570
# Getting system information
6671
[System.Object]$SysInfo = Get-RSInstallInfo
67-
6872
# If user has choosen to skip the WinGet version don't check, if WinGet is not installed this will install WinGet anyway.
69-
if ($SkipVersionCheck -eq $false -or $SysInfo.WinGet -eq "No") {
73+
if ($SkipVersionCheck -eq $false -or $SysInfo.WinGet -eq "0.0.0.0") {
7074
Confirm-RSWinGet -GitHubUrl $GitHubUrl -GithubHeaders $GithubHeaders -WinGet $SysInfo.WinGet
7175
}
7276

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.1.0"
12+
[string]$Version = "0.1.2"
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.1.0'
39+
ModuleVersion = '0.1.2'
4040

4141
# Supported PSEditions
4242
# CompatiblePSEditions = @()

WinSoftwareUpdate/WinSoftwareUpdate.psm1

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,16 @@ Function Update-RSWinSoftware {
8484
#
8585
[string]$VCLibsOutFile = "$env:TEMP\Microsoft.VCLibs.140.00.$($Arch).appx"
8686

87+
# Importing appx with -usewindowspowershell if your using PowerShell 7 or higher
88+
if ($PSVersionTable.PSVersion.Major -ge 7) {
89+
import-module appx -usewindowspowershell
90+
Write-Output "== This messages is expected if you are using PowerShell 7 or higher =="
91+
}
8792

8893
# Getting system information
8994
[System.Object]$SysInfo = Get-RSInstallInfo
90-
9195
# If user has choosen to skip the WinGet version don't check, if WinGet is not installed this will install WinGet anyway.
92-
if ($SkipVersionCheck -eq $false -or $SysInfo.WinGet -eq "No") {
96+
if ($SkipVersionCheck -eq $false -or $SysInfo.WinGet -eq "0.0.0.0") {
9397
Confirm-RSWinGet -GitHubUrl $GitHubUrl -GithubHeaders $GithubHeaders -WinGet $SysInfo.WinGet
9498
}
9599

@@ -175,10 +179,10 @@ Function Confirm-RSWinGet {
175179
}
176180

177181
# Checking if the installed version of WinGet are the same as the latest version of WinGet
178-
[version]$vWinGet = [string]$WinGet
182+
[version]$vWinGet = [string]$SysInfo.WinGet
179183
[version]$vGitHub = [string]$GitHubInfo.Tag
180184

181-
if ([Version]$vWinGet -lt [Version]$vGitHub) {
185+
if ([Version]$vWinGet -lt [Version]$vGitHub -or $WinGet -like "1.19.3531.0") {
182186
Write-Output "WinGet has a newer version $($GitHubInfo.Tag), downloading and installing it..."
183187
Invoke-WebRequest -UseBasicParsing -Uri $GitHubInfo.DownloadUrl -OutFile $GitHubInfo.OutFile
184188

@@ -245,9 +249,9 @@ Function Get-RSInstallInfo {
245249
# Collects everything in pscustomobject to get easier access to the information
246250
[System.Object]$SysInfo = [PSCustomObject]@{
247251
VCLibs = $(Get-AppxPackage -Name "Microsoft.VCLibs.140.00" -AllUsers | Where-Object { $_.Architecture -eq $Arch })
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" })
252+
WinGet = $(try { (Get-AppxPackage -AllUsers | Where-Object { $_.name -like "Microsoft.DesktopAppInstaller" } | Sort-Object { $_.Version -as [version] } -Descending | Select-Object Version -First 1).version } catch { "0.0.0.0" })
249253
VisualCRedistUrl = $VisualCRedistUrl
250-
$VCLibsUrl = $VCLibsUrl
254+
VCLibsUrl = $VCLibsUrl
251255
Arch = $Arch
252256
}
253257

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 : 307
14+
Line : 311
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)