2023-03-07 12:28:00 -08:00
|
|
|
function Test-WinUtilPackageManager {
|
|
|
|
|
<#
|
2023-10-19 17:12:55 -05:00
|
|
|
|
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Checks if Winget and/or Choco are installed
|
|
|
|
|
|
|
|
|
|
.PARAMETER winget
|
|
|
|
|
Check if Winget is installed
|
|
|
|
|
|
|
|
|
|
.PARAMETER choco
|
|
|
|
|
Check if Chocolatey is installed
|
|
|
|
|
|
2023-03-07 12:28:00 -08:00
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
Param(
|
|
|
|
|
[System.Management.Automation.SwitchParameter]$winget,
|
|
|
|
|
[System.Management.Automation.SwitchParameter]$choco
|
|
|
|
|
)
|
|
|
|
|
|
2024-03-30 11:46:29 -05:00
|
|
|
$status = "not-installed"
|
2024-02-06 14:02:58 -06:00
|
|
|
|
|
|
|
|
if ($winget) {
|
2024-06-04 20:27:27 -07:00
|
|
|
# Check if Winget is available while getting it's Version if it's available
|
|
|
|
|
$wingetExists = $true
|
|
|
|
|
try {
|
|
|
|
|
$wingetVersionFull = winget --version
|
|
|
|
|
} catch [System.Management.Automation.CommandNotFoundException], [System.Management.Automation.ApplicationFailedException] {
|
|
|
|
|
Write-Warning "Winget was not found due to un-availablity reasons"
|
|
|
|
|
$wingetExists = $false
|
|
|
|
|
} catch {
|
|
|
|
|
Write-Warning "Winget was not found due to un-known reasons, The Stack Trace is:`n$($psitem.Exception.StackTrace)"
|
|
|
|
|
$wingetExists = $false
|
2024-08-06 23:35:17 +03:00
|
|
|
}
|
2024-06-04 20:27:27 -07:00
|
|
|
|
|
|
|
|
# If Winget is available, Parse it's Version and give proper information to Terminal Output.
|
2024-08-06 23:35:17 +03:00
|
|
|
# If it isn't available, the return of this funtion will be "not-installed", indicating that
|
2024-06-04 20:27:27 -07:00
|
|
|
# Winget isn't installed/available on The System.
|
2024-08-06 23:35:17 +03:00
|
|
|
if ($wingetExists) {
|
2024-03-30 11:46:29 -05:00
|
|
|
# Check if Preview Version
|
|
|
|
|
if ($wingetVersionFull.Contains("-preview")) {
|
|
|
|
|
$wingetVersion = $wingetVersionFull.Trim("-preview")
|
|
|
|
|
$wingetPreview = $true
|
2024-03-21 16:23:24 -07:00
|
|
|
} else {
|
2024-03-30 11:46:29 -05:00
|
|
|
$wingetVersion = $wingetVersionFull
|
|
|
|
|
$wingetPreview = $false
|
2024-03-21 16:23:24 -07:00
|
|
|
}
|
2024-03-30 11:46:29 -05:00
|
|
|
|
|
|
|
|
# Check if Winget's Version is too old.
|
|
|
|
|
$wingetCurrentVersion = [System.Version]::Parse($wingetVersion.Trim('v'))
|
2024-04-20 16:38:43 -05:00
|
|
|
# Grabs the latest release of Winget from the Github API for version check process.
|
|
|
|
|
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/microsoft/Winget-cli/releases/latest" -Method Get -ErrorAction Stop
|
|
|
|
|
$wingetLatestVersion = [System.Version]::Parse(($response.tag_name).Trim('v')) #Stores version number of latest release.
|
|
|
|
|
$wingetOutdated = $wingetCurrentVersion -lt $wingetLatestVersion
|
2024-03-30 11:46:29 -05:00
|
|
|
Write-Host "===========================================" -ForegroundColor Green
|
2024-04-20 16:38:43 -05:00
|
|
|
Write-Host "--- Winget is installed ---" -ForegroundColor Green
|
2024-03-30 11:46:29 -05:00
|
|
|
Write-Host "===========================================" -ForegroundColor Green
|
|
|
|
|
Write-Host "Version: $wingetVersionFull" -ForegroundColor White
|
|
|
|
|
|
|
|
|
|
if (!$wingetPreview) {
|
|
|
|
|
Write-Host " - Winget is a release version." -ForegroundColor Green
|
|
|
|
|
} else {
|
|
|
|
|
Write-Host " - Winget is a preview version. Unexpected problems may occur." -ForegroundColor Yellow
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$wingetOutdated) {
|
|
|
|
|
Write-Host " - Winget is Up to Date" -ForegroundColor Green
|
|
|
|
|
$status = "installed"
|
2024-08-06 23:35:17 +03:00
|
|
|
} else {
|
2024-03-30 11:46:29 -05:00
|
|
|
Write-Host " - Winget is Out of Date" -ForegroundColor Red
|
|
|
|
|
$status = "outdated"
|
|
|
|
|
}
|
2024-06-29 01:15:39 +03:00
|
|
|
} else {
|
2024-03-30 11:46:29 -05:00
|
|
|
Write-Host "===========================================" -ForegroundColor Red
|
2024-04-20 16:38:43 -05:00
|
|
|
Write-Host "--- Winget is not installed ---" -ForegroundColor Red
|
2024-03-30 11:46:29 -05:00
|
|
|
Write-Host "===========================================" -ForegroundColor Red
|
|
|
|
|
$status = "not-installed"
|
2023-03-07 12:28:00 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-21 16:23:24 -07:00
|
|
|
if ($choco) {
|
|
|
|
|
if ((Get-Command -Name choco -ErrorAction Ignore) -and ($chocoVersion = (Get-Item "$env:ChocolateyInstall\choco.exe" -ErrorAction Ignore).VersionInfo.ProductVersion)) {
|
2024-03-30 11:46:29 -05:00
|
|
|
Write-Host "===========================================" -ForegroundColor Green
|
2024-04-20 16:38:43 -05:00
|
|
|
Write-Host "--- Chocolatey is installed ---" -ForegroundColor Green
|
2024-03-30 11:46:29 -05:00
|
|
|
Write-Host "===========================================" -ForegroundColor Green
|
|
|
|
|
Write-Host "Version: v$chocoVersion" -ForegroundColor White
|
|
|
|
|
$status = "installed"
|
|
|
|
|
} else {
|
|
|
|
|
Write-Host "===========================================" -ForegroundColor Red
|
2024-04-20 16:38:43 -05:00
|
|
|
Write-Host "--- Chocolatey is not installed ---" -ForegroundColor Red
|
2024-03-30 11:46:29 -05:00
|
|
|
Write-Host "===========================================" -ForegroundColor Red
|
|
|
|
|
$status = "not-installed"
|
2023-03-07 12:28:00 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-30 11:46:29 -05:00
|
|
|
return $status
|
2024-03-21 16:23:24 -07:00
|
|
|
}
|