commit 0a187b753f6f0c71bcbdaba9a2222d96b5c1dc5e Author: Ryan Date: Sat Sep 7 19:04:50 2024 +0000 Add InstallApps.ps1 diff --git a/InstallApps.ps1 b/InstallApps.ps1 new file mode 100644 index 0000000..0908afa --- /dev/null +++ b/InstallApps.ps1 @@ -0,0 +1,98 @@ +# Function to display a menu and get user input +function Show-Menu { + param ( + [string]$prompt, + [array]$options + ) + + Write-Host $prompt + for ($i = 0; $i -lt $options.Length; $i++) { + Write-Host "$($i + 1). $($options[$i])" + } + + $choice = Read-Host "Select an option (1-$($options.Length))" + return $choice +} + +# Function to select multiple options using spacebar +function Select-MultipleOptions { + param ( + [string]$prompt, + [array]$options + ) + + Write-Host $prompt + $selectedOptions = @() + + # Display options with selection state + for ($i = 0; $i -lt $options.Length; $i++) { + Write-Host "$($i + 1). $($options[$i]) [ ]" + } + + Write-Host "Use spacebar to select/unselect and Enter to confirm." + + # Capture user input + while ($true) { + $key = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") + if ($key.Character -match '\d') { + $index = [int]$key.Character - 1 + if ($index -ge 0 -and $index -lt $options.Length) { + if ($selectedOptions.Contains($index)) { + $selectedOptions.Remove($index) + } else { + $selectedOptions.Add($index) + } + } + } elseif ($key.VirtualKeyCode -eq 13) { + break + } + } + + return $selectedOptions | ForEach-Object { $options[$_] } +} + +# Main Script Logic +$mainMenuChoice = Show-Menu "Do you want to:" @("Update all apps", "Install apps") + +switch ($mainMenuChoice) { + 1 { + # Update all apps + Write-Host "Updating all apps..." + Start-Process winget -ArgumentList "upgrade --all" -NoNewWindow -Wait + } + 2 { + # Install apps options + $installChoice = Show-Menu "Choose an installation option:" @("Fresh install of ALL apps", "Select package groups", "Install select packages only") + + switch ($installChoice) { + 1 { + # Fresh install of ALL apps + Write-Host "Performing fresh install of all apps..." + Get-ChildItem -Path "C:\winget\install\groups\*.ps1" | ForEach-Object { & $_.FullName } + } + 2 { + # Select package groups + $packageGroups = Get-ChildItem -Path "C:\winget\install\groups\*.ps1" | Select-Object -ExpandProperty Name + $selectedGroups = Select-MultipleOptions "Select package groups to install:" $packageGroups + + foreach ($group in $selectedGroups) { + Write-Host "Installing group: $group" + & "C:\winget\install\groups\$group" + } + } + 3 { + # Install select packages only + $packages = Get-Content -Path "C:\winget\install\individual\list.ps1" + $selectedPackages = Select-MultipleOptions "Select individual packages to install:" $packages + + foreach ($package in $selectedPackages) { + Write-Host "Installing package: $package" + & $package + } + } + } + } + default { + Write-Host "Invalid choice, please try again." + } +}