Files
winutil/functions/private/Test-WinUtilPackageManager.ps1
T

53 lines
1.5 KiB
PowerShell
Raw Normal View History

+3
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
+3
2023-03-07 12:28:00 -08:00
#>
Param(
[System.Management.Automation.SwitchParameter]$winget,
[System.Management.Automation.SwitchParameter]$choco
)
2024-02-06 14:02:58 -06:00
# Install Winget if not detected
$wingetExists = Get-Command -Name winget -ErrorAction SilentlyContinue
if ($wingetExists) {
$wingetVersion = [System.Version]::Parse((winget --version).Trim('v'))
$minimumWingetVersion = [System.Version]::new(1,2,10691) # Win 11 23H2 comes with bad winget v1.2.10691
$wingetOutdated = $wingetVersion -le $minimumWingetVersion
Write-Host "Winget v$wingetVersion"
}
if (!$wingetExists -or $wingetOutdated) {
if (!$wingetExists) {
Write-Host "Winget not detected"
} else {
Write-Host "- Winget out-dated"
}
}
if ($winget) {
if ($wingetExists -and !$wingetOutdated) {
Write-Host "- Winget up-to-date"
+3
2023-03-07 12:28:00 -08:00
return $true
}
}
if($choco){
if ((Get-Command -Name choco -ErrorAction Ignore) -and ($chocoVersion = (Get-Item "$env:ChocolateyInstall\choco.exe" -ErrorAction Ignore).VersionInfo.ProductVersion)){
2024-02-06 14:02:58 -06:00
Write-Host "Chocolatey v$chocoVersion"
+3
2023-03-07 12:28:00 -08:00
return $true
}
}
return $false
}