winutil/functions/private/Install-WinUtilChoco.ps1
2024-07-13 12:54:59 +02:00

33 lines
1.2 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
}
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Indeterminate" })
Write-Host "Seems Chocolatey is not installed, installing now."
Set-ExecutionPolicy Bypass -Scope Process -Force; Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) -ErrorAction Stop
powershell choco feature enable -n allowGlobalConfirmation
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "None" })
}
Catch {
Write-Host "===========================================" -Foregroundcolor Red
Write-Host "-- Chocolatey failed to install ---" -Foregroundcolor Red
Write-Host "===========================================" -Foregroundcolor Red
$sync.form.Dispatcher.Invoke([action]{ Set-WinUtilTaskbaritem -state "Error" })
}
}