winutil/functions/private/Install-WinUtilChoco.ps1
Martin Wiethan 14d20cd161
Choco Logic Refactor and Add Checkbox to prefer Chocolatey over Winget (#2596)
* First Selector and Logic

* Extend Functionality

* Switch to PreferChocolatey Checkbox

* Persist Choco Preference across program restarts

* Change Logging, Fix interactivity and optimize uninstall

* Implement "Get-Installed" (quick-and-dirty)

* Code Formatting

* Rename File/Function, Refactor Choco Install, Add Status Indicator

* Add documentation

---------

Co-authored-by: Chris Titus <contact@christitus.com>
2024-09-10 13:02:22 -05:00

28 lines
1.0 KiB
PowerShell

function Install-WinUtilChoco {
<#
.SYNOPSIS
Installs Chocolatey if it is not already installed
#>
try {
Write-Host "Checking if Chocolatey is Installed..."
if((Test-WinUtilPackageManager -choco) -eq "installed") {
return
}
Write-Host "Seems Chocolatey is not installed, installing now."
Start-Process -FilePath "powershell" -ArgumentList "Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) -ErrorAction Stop" -Wait -NoNewWindow
Start-Process -FilePath "powershell" -ArgumentList "choco feature enable -n allowGlobalConfirmation" -Wait -NoNewWindow
} catch {
Write-Host "===========================================" -Foregroundcolor Red
Write-Host "-- Chocolatey failed to install ---" -Foregroundcolor Red
Write-Host "===========================================" -Foregroundcolor Red
}
}