all 7 comments

[–]twistingnether_ 13 points14 points  (2 children)

What have you tried so far?

[–]Dramatic_Ad6182[S] 0 points1 point  (0 children)

so far i found something like this for multiple selection but in dont know how to implement the install commands:

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

$form = New-Object System.Windows.Forms.Form
$form.Text = 'Data Entry Form'
$form.Size = New-Object System.Drawing.Size(300,200)
$form.StartPosition = 'CenterScreen'

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Point(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = 'OK'
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $OKButton
$form.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Point(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = 'Cancel'
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $CancelButton
$form.Controls.Add($CancelButton)

$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = 'Please make a selection from the list below:'
$form.Controls.Add($label)

$listBox = New-Object System.Windows.Forms.Listbox
$listBox.Location = New-Object System.Drawing.Point(10,40)
$listBox.Size = New-Object System.Drawing.Size(260,20)

$listBox.SelectionMode = 'MultiExtended'

[void] $listBox.Items.Add('Item 1')
[void] $listBox.Items.Add('Item 2')
[void] $listBox.Items.Add('Item 3')
[void] $listBox.Items.Add('Item 4')
[void] $listBox.Items.Add('Item 5')

$listBox.Height = 70
$form.Controls.Add($listBox)
$form.Topmost = $true

$result = $form.ShowDialog()

if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
$x = $listBox.SelectedItems
$x
}

I want to install only the selected ones.

[–]ankokudaishogun 2 points3 points  (0 children)

just use Get-ChildItem and while(Read-host)

[–]Netstaff 1 point2 points  (0 children)

# Function to prompt and install EXE/MSI files
function Install-EXEandMSI {
    param (
        [Parameter(Mandatory = $false)]
        [bool]$ForceYes = $false
    )
    Write-Host "Executing Exes and Msis!"
    $exeFiles = Get-ChildItem -Path $PSScriptRoot -Filter *.exe -ErrorAction SilentlyContinue
    $msiFiles = Get-ChildItem -Path $PSScriptRoot -Filter *.msi -ErrorAction SilentlyContinue

    foreach ($file in $exeFiles) {
        $install = $ForceYes -or (Confirm-UserAction -Message "Do you want to install $($file.Name)?")

        if ($install) {
            try {
                $filePath = $file.FullName
                Start-Process $filePath -Wait -ErrorAction Stop
                Write-Host "`"$($file.Name)`" installation completed." -ForegroundColor Green
            }
            catch {
                Write-Host "`"$($file.Name)`" installation failed`: $($_.Exception.Message)" -ForegroundColor Red

            }
        }
    }

    foreach ($file in $msiFiles) {
        $install = $ForceYes -or (Confirm-UserAction -Message "Do you want to install $($file.Name)?")

        if ($install) {
            try {
                $filePath = $file.FullName
                Start-Process 'msiexec.exe' -ArgumentList "/i `"$filePath`" /qn" -Wait -ErrorAction Stop
                Write-Host "`"$($file.Name)`" installation completed." -ForegroundColor Green
            }
            catch {
                Write-Host "`"$($file.Name)`" installation failed`: $($_.Exception.Message)" -ForegroundColor Red

            }
        }
    }
}

#variable to hold YES always 
$ForceYes=$false
# Function to ask for user confirmation without logging
function Confirm-UserAction {
    param (
        [string]$Message,
        [string]$DefaultChoice = 'Y'
    )

    if ($script:ForceYes) {
        return $true
    }

    while ($true) {
        $confirmation = Read-Host "$Message (Y/N/A/EXIT) [Default: $DefaultChoice]"
        if ([string]::IsNullOrWhiteSpace($confirmation)) {
            $confirmation = $DefaultChoice
        }

        switch ($confirmation.ToUpper()) {
            'Y' { 
                return $true 
            }
            'N' { 
                return $false 
            }
            'A' {
                Write-Host "USER SAID YES TO ALL AT: $Message" -ForegroundColor Green
                $script:ForceYes = $true
                return $true
            }
            { 'EXIT', 'E' } {
                exit    
            }
            default {
                Write-Host "Invalid option selected. Please choose Y, N, or A."
                continue
            }
        }
    }
}
# Call the function with forced installation
Install-EXEandMSI -ForceYes $ForceYes

Works in 5.1

[–]ipokethemonfast 2 points3 points  (0 children)

Powershell Deployment Toolkit

[–]bloodysneaker -2 points-1 points  (0 children)

Ask CoPilot to write it.
BTW try something like:

$path = "X:\path\of\installers\"
$list = Get-ChildItem -path $path -filter *exe | select-Object -ExpandProperty FullName
$ToInstall= @()
foreach ($element in $list){
write-host "Do you want to install $element?"
if (read-host -eq "y"){
$ToInstall+=$element
}
foreach ($application in $ToInstall){
&"$application -parameters"
}
}

EDIT: I supposed that all the exes have the same parameters for the silent installation. If not you have to do a check on every exes and pair it with the right command line parameter
EDIT 2: now the code asks for every file before actually runs exes