Skip to content

Commit

Permalink
PowerShell module will only be installed when WinGet is missing and n…
Browse files Browse the repository at this point in the history
…eeds to be installed
  • Loading branch information
marticliment committed Sep 26, 2024
1 parent 71420bf commit ab64e79
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions InstallerExtras/EnsureWinGet.ps1
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
Set-ExecutionPolicy Bypass -Scope Process -Force
if (!(Get-Command -Verb Repair -Noun WinGetPackageManager)) {
Write-Output "Microsoft.WinGet.Client is not installed or is not on the latest version"
try
{
Write-Output "Attempting to uninstall an older version of Microsoft.WinGet.Client..."
Uninstall-Module -Name Microsoft.WinGet.Client -Confirm:$false -Force -Scope CurrentUser
if ($null -eq (Get-Command "winget.exe" -ErrorAction SilentlyContinue))
{
Write-Output "WinGet is not present on the system"
if (!(Get-Command -Verb Repair -Noun WinGetPackageManager)) {
Write-Output "Microsoft.WinGet.Client is not installed or is not on the latest version"
try
{
Write-Output "Attempting to uninstall an older version of Microsoft.WinGet.Client..."
Uninstall-Module -Name Microsoft.WinGet.Client -Confirm:$false -Force -Scope CurrentUser
}
catch
{
Write-Output "Microsoft.WinGet.Client was not installed."
}
Write-Output "Installing Microsoft.WinGet.Client..."
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Confirm:$false -Scope CurrentUser
Install-Module -Name Microsoft.WinGet.Client -Confirm:$false -Force -Scope CurrentUser
Write-Output "Microsoft.WinGet.Client was installed successfully"
}
catch

Write-Output "Checking for updates for Microsoft.WinGet.Client module..."
if ((Get-Module -Name Microsoft.WinGet.Client -ListAvailable).Version -ge '1.8.1791')
{
Write-Output "Microsoft.WinGet.Client was not installed."
Write-Output "Microsoft.WinGet.Client is up-to-date"
} else {
Write-Output "Updating Microsoft.WinGet.Client module..."
Update-Module -Name Microsoft.WinGet.Client -Confirm:$false -Force -Scope CurrentUser
}
Write-Output "Installing Microsoft.WinGet.Client..."
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Confirm:$false -Scope CurrentUser
Install-Module -Name Microsoft.WinGet.Client -Confirm:$false -Force -Scope CurrentUser
Write-Output "Microsoft.WinGet.Client was installed successfully"
}

Write-Output "Checking for updates for Microsoft.WinGet.Client module..."
if ((Get-Module -Name Microsoft.WinGet.Client -ListAvailable).Version -ge '1.8.1791')
{
Write-Output "Microsoft.WinGet.Client is up-to-date"
} else {
Write-Output "Updating Microsoft.WinGet.Client module..."
Update-Module -Name Microsoft.WinGet.Client -Confirm:$false -Force -Scope CurrentUser
}

if ($null -eq (Get-Command "winget.exe" -ErrorAction SilentlyContinue))
{
Write-Output "WinGet is not present on the system"
Write-Output "Installing WinGet..."
Repair-WinGetPackageManager
Write-Output "WinGet was installed successfully"
Expand Down

0 comments on commit ab64e79

Please sign in to comment.