0
# Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass  (Before running the script execute the command in terminal for admin rights)

# Step 1) install 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'))
}

$argList = "-file `"C:\Users\cdac\Desktop\Shravan\PowerShell_Scripts\Automation_working_code_bkup.ps1`""
Start powershell -argumentlist $argList -NoNewWindow 

# Step 2) define the array of packages you are offering
 $Packages = 'googlechrome',
             'firefox',
             'codeblocks', 
             'windbg',                        ##### newly added ####          
             'x64dbg.portable',               ##### newly added #### 
             'visualstudio2019community',     ##### newly added ####
             'nasm',
             'explorersuite',
             'pestudio',
             'vscode',
             'sysinternals',
             'python',                        ##### newly added ####
             'ccleaner',
             'anaconda3',
             'wireshark',
             'sublimetext3',  
             'notepadplusplus',
             'ida-free'
 
             

# Step 3) define the Show-Menu function
function Show-Menu 
{
    Clear-Host
    Write-Host "**********************************************"
    Write-Host "LIST OF SOFTWARES"
    # write 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 (inclusive)
            if ([int]::TryParse($input,[ref]$null) -and 1..$Packages.Count -contains [int]$input) 
            {
                # here you install the chosen package using the array index number (= user input number minus 1)
                $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"
}

I have to execute the current script output in another powershell terminal. Another powershell terminal is opening but the terminal is blinking continuously. please tell me where the mistake in the script.

3
  • Which environment variables? What exactly are you trying to do? Your question is much too sketchy.
    – harrymc
    Commented Oct 13, 2021 at 8:55
  • Sir i have to open another powershell terminal from the current script to execute the current script output . Another powershell terminal is opening but the terminal is continuously blinking . Commented Oct 14, 2021 at 4:57
  • 1) Do you want the second powershell window to be interactive so users can type into it? 2) Should the first powershell window wait for the second one to finish? 3) Should the first powershell window get any output from the second one? 4) If you want a second powershell window, why do you specify -NoNewWindow?
    – Cpt.Whale
    Commented Oct 19, 2021 at 14:24

0

You must log in to answer this question.

Browse other questions tagged .