Advertisement
kohijones

Start-WinGetInstall

Jun 6th, 2022 (edited)
1,663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Clear-Host
  2. $Programs = @'
  3. google.chrome
  4. Mozilla.Firefox
  5. '@ -split [environment]::NewLine
  6.  
  7. function Out-Menu {
  8.     param (
  9.         [Parameter(Mandatory = $true, ValueFromPipeline = $True, ValueFromPipelinebyPropertyName = $True)]
  10.         [object[]]$Object,
  11.         [string]$Header,
  12.         [string]$Footer,
  13.         [switch]$AllowCancel,
  14.         [switch]$AllowMultiple
  15.     )
  16.  
  17.     if ($input) {
  18.         $Object = @($input)
  19.     }
  20.  
  21.     if (!$Object) {
  22.         throw 'Must provide an object.'
  23.     }
  24.  
  25.     Write-Host ''
  26.  
  27.     do {
  28.         $prompt = New-Object System.Text.StringBuilder
  29.         switch ($true) {
  30.             { [bool]$Header -and $Header -notmatch '^(?:\s+)?$' } { $null = $prompt.Append($Header); break }
  31.             $true { $null = $prompt.Append('Choose an option') }
  32.             $AllowCancel { $null = $prompt.Append(', or enter "c" to cancel.') }
  33.             $AllowMultiple { $null = $prompt.Append("`nTo select multiple, enter numbers separated by a comma EX: 1, 2") }
  34.         }
  35.         Write-Host $prompt.ToString()
  36.  
  37.         for ($i = 0; $i -lt $Object.Count; $i++) {
  38.             Write-Host "$('{0:D2}' -f ($i+1)). $($Object[$i])"
  39.         }
  40.  
  41.         if ($Footer) {
  42.             Write-Host $Footer
  43.         }
  44.  
  45.         Write-Host ''
  46.  
  47.         if ($AllowMultiple) {
  48.             $answers = @(Read-Host).Split(',').Trim()
  49.  
  50.             if ($AllowCancel -and $answers -match 'c') {
  51.                 return
  52.             }
  53.  
  54.             $ok = $true
  55.             foreach ($ans in $answers) {
  56.                 if ($ans -in 1..$Object.Count) {
  57.                     $Object[$ans - 1]
  58.                 } else {
  59.                     Write-Host 'Not an option!' -ForegroundColor Red
  60.                     Write-Host ''
  61.                     $ok = $false
  62.                 }
  63.             }
  64.         } else {
  65.             $answer = Read-Host
  66.  
  67.             if ($AllowCancel -and $answer -eq 'c') {
  68.                 return
  69.             }
  70.  
  71.             $ok = $true
  72.             if ($answer -in 1..$Object.Count) {
  73.                 $Object[$answer - 1]
  74.             } else {
  75.                 Write-Host 'Not an option!' -ForegroundColor Red
  76.                 Write-Host ''
  77.                 $ok = $false
  78.             }
  79.         }
  80.     } while (!$ok)
  81. }
  82.  
  83. $Choices = Out-Menu $Programs -AllowCancel -AllowMultiple
  84.  
  85. foreach ($Choice in $Choices) {
  86.     Winget install --id $Choice
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement