Software silent installation

Software silent installation


Warning
Test script before deploying.

Function Install-Software ($installer, $arguments) {
    If (Test-Path $installer) {
        try {
            $process = Start-Process -FilePath $installer -ArgumentList $arguments -PassThru -ErrorAction Stop
            Write-Output "Starting software installation..."

            # Start the progress bar
            $progress = 0
            while (!$process.HasExited) {
                $progress = ($progress + 1) % 100
                Write-Progress -Activity "Installing software..." -Status "$progress% Complete:" -PercentComplete $progress
                Start-Sleep -Seconds 1
            }

            # Clear the progress bar
            Write-Progress -Activity "Installing software..." -Completed

            if ($process.ExitCode -eq 0) {
                Write-Output "Software installation successful."
            } else {
                Write-Output "Software installation failed with exit code $($process.ExitCode)."
            }
        }
        catch {
            Write-Output "Failed to install software. Error: $_"
        }
    }
    else {
        Write-Output "$installer does not exist."
    }
}

# Install software
$installer = "Path\to\your\installer.exe" # Replace this with the path to your installer
$arguments = "/S LICENSE=True USERNAME=XXX USERCOMPANY=XXXXX SERIALNUMBER=XXX-XXXXXXXX SAVESITELICENSECODE=XXXXXXXX" # Replace this with your installer's specific arguments

Install-Software -installer $installer -arguments $arguments