0
#step 1) Installing Chocolatey when needed


if (-not (Test-Path -Path "$env:ProgramData\Chocolatey\choco.exe" -PathType Leaf))
 {
   # from https://chocolatey.org/install
   Set-ExecutionPolicy Bypass -Scope Process -Force;
   [System.Net.ServicePointManager]::SecurityProtocol = 
   [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;
   iex ((New-Object 
   System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) 
}


# Step 2) defining the array of packages which we want to install

$Packages = 'googlechrome',
            'firefox',
            'codeblocks',
            'windbg',
            'nasm',
            'explorersuite',
            'pestudio',
            'vscode',
            'sysinternals',
            'python',
            'ccleaner',
            'anaconda3',
            'wireshark',
            'sublimetext3',
            'notepadplusplus',
            'ida-free'  
            


# Step 3) defining the Show-Menu function

 function Show-Menu
 {
    Clear-Host
    Write-Host "**********************************************"
    Write-Host "LIST OF SOFTWARES"

    # writing  the options using the array of packages

    for ($i = 0; $i -lt $Packages.Count; $i++) 
    {
        # {0,10} means right align with spaces to max 10 characters
        Write-Host ('{0,10}. {1}' -f ($i + 1), $Packages[$i])
    }

    Write-Host " q. Exit the script"
    Write-Host "*************************************************"
    Write-Host
}

# Step 4) enter an endless loop you only exit if the user enters 'q'

while ($true) 
{
    Show-Menu

    $UserInput = Read-Host "Select the softwares number(s) to be installed (space 
                 separated)"
   
        # testing if the user wants to quit and if so, break the loop
      
        if ($UserInput -eq 'q') 
        {
            break
        }

         foreach($input in $UserInput.Split(' '))
         {
     
            # testing if the user entered a number between 1 and the total number of 
              packages

          if ([int]::TryParse($input,[ref]$null) -and 1..$Packages.Count -contains 
                    [int]$input) 
            {
                # here you install the chosen package using the array index number
                $packageIndex = [int]$input - 1
                Write-Host "Installing $($Packages[$packageIndex])"
                Choco install $Packages[$packageIndex] -y --ignore-checksums
            } 

             else 
             {
                $availableOptions = 1..$Packages.Count -join ','
                Write-Host "Error in selection, choose $availableOptions or q" - 
                ForegroundColor Red
             }
         }

    $null = Read-Host "Press Enter to continue"
}

The above script is downloading and installing the softwares, but i want to install the outdated packages. I came to know that in chocolatey we have outdated command which displays all the outdated packages installed in the local pc but i want to install the outdated packages how to do this

2
  • Please fix your code. You are now adding newlines where they should not be and in the process also cut off the character s in -contains plus the final closing bracket } is missing
    – Theo
    Commented Oct 11, 2021 at 10:00
  • any solution about it ? Install Windows 10 and then chocolatey and apps
    – Kiquenet
    Commented Aug 20, 2022 at 12:35

0

You must log in to answer this question.

Browse other questions tagged .