Skip to content

Commit bca291e

Browse files
authored
Fix installation of winget modules for winget and git-clone (#124)
Whenever we run winget commandlets in our scripts, we always run them under powershell 7 (pwsh.exe) given its broader compatibility. However, during the installation of winget modules, we sometimes evaluate if the modules are installed under powershell 5 instead of the desired target of powershell 7. This diff fixes it to always target powershell 7.
1 parent 8b4c088 commit bca291e

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

Tasks/git-clone/main.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,9 @@ function InstallWinGet {
151151
pwsh.exe -MTA -Command "Set-PSRepository -Name PSGallery -InstallationPolicy Trusted"
152152

153153
# check if the Microsoft.Winget.Client module is installed
154-
$wingetClientPackage = Get-Module -ListAvailable -Name Microsoft.WinGet.Client | Where-Object { $_.Version -ge "1.9.2411" }
154+
$wingetClientPackage = pwsh.exe -Command "Get-Module -ListAvailable -Name Microsoft.WinGet.Client | Where-Object { `$_.Version -ge '1.9.2411' }"
155155
if (!($wingetClientPackage)) {
156156
Write-Host "Installing Microsoft.Winget.Client"
157-
Install-Module Microsoft.WinGet.Client -Scope $PsInstallScope
158157
pwsh.exe -MTA -Command "Install-Module Microsoft.WinGet.Client -Scope $PsInstallScope"
159158
Write-Host "Done Installing Microsoft.Winget.Client"
160159
}
@@ -163,7 +162,7 @@ function InstallWinGet {
163162
}
164163

165164
# check if the Microsoft.WinGet.Configuration module is installed
166-
$wingetConfigurationPackage = Get-Module -ListAvailable -Name Microsoft.WinGet.Configuration | Where-Object { $_.Version -ge "1.8.1911" }
165+
$wingetConfigurationPackage = pwsh.exe -Command "Get-Module -ListAvailable -Name Microsoft.WinGet.Configuration | Where-Object { `$_.Version -ge '1.8.1911' }"
167166
if (!($wingetConfigurationPackage)) {
168167
Write-Host "Installing Microsoft.WinGet.Configuration"
169168
pwsh.exe -MTA -Command "Install-Module Microsoft.WinGet.Configuration -AllowPrerelease -Scope $PsInstallScope"

Tasks/winget/main.ps1

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,19 +162,18 @@ function InstallWinGet {
162162
pwsh.exe -MTA -Command "Set-PSRepository -Name PSGallery -InstallationPolicy Trusted"
163163

164164
# check if the Microsoft.Winget.Client module is installed
165-
$wingetClientPackage = Get-Module -ListAvailable -Name Microsoft.WinGet.Client | Where-Object { $_.Version -ge "1.9.2411" }
165+
$wingetClientPackage = pwsh.exe -Command "Get-Module -ListAvailable -Name Microsoft.WinGet.Client | Where-Object { `$_.Version -ge '1.9.2411' }"
166166
if (!($wingetClientPackage)) {
167-
Write-Host "Installing Microsoft.Winget.Client -RequiredVersion 1.9.25190"
168-
Install-Module Microsoft.WinGet.Client -Scope $PsInstallScope -RequiredVersion 1.9.25190
169-
pwsh.exe -MTA -Command "Install-Module Microsoft.WinGet.Client -Scope $PsInstallScope -RequiredVersion 1.9.25190"
167+
Write-Host "Installing Microsoft.Winget.Client"
168+
pwsh.exe -MTA -Command "Install-Module Microsoft.WinGet.Client -Scope $PsInstallScope"
170169
Write-Host "Done Installing Microsoft.Winget.Client"
171170
}
172171
else {
173172
Write-Host "Microsoft.Winget.Client is already installed"
174173
}
175174

176175
# check if the Microsoft.WinGet.Configuration module is installed
177-
$wingetConfigurationPackage = Get-Module -ListAvailable -Name Microsoft.WinGet.Configuration | Where-Object { $_.Version -ge "1.8.1911" }
176+
$wingetConfigurationPackage = pwsh.exe -Command "Get-Module -ListAvailable -Name Microsoft.WinGet.Configuration | Where-Object { `$_.Version -ge '1.8.1911' }"
178177
if (!($wingetConfigurationPackage)) {
179178
Write-Host "Installing Microsoft.WinGet.Configuration"
180179
pwsh.exe -MTA -Command "Install-Module Microsoft.WinGet.Configuration -Scope $PsInstallScope"

0 commit comments

Comments
 (0)