diff --git a/Tasks/System-Tasks/Additional-Software.ps1 b/Tasks/System-Tasks/Additional-Software.ps1 new file mode 100644 index 0000000..96747be --- /dev/null +++ b/Tasks/System-Tasks/Additional-Software.ps1 @@ -0,0 +1,83 @@ +# Silent Software Installation Script using Winget + +# Arrays of software to install and remove +# Add or remove applications by modifying these arrays +# Check the name of Winget Packages here: https://winget.run +$applicationsToInstall = @( + # Add more applications to install here + #"Notepad++.Notepad++" +) + +$applicationsToRemove = @( + # Add applications to remove here + #"Mozilla.Firefox" + #"7zip.7zip" +) + +# Function to check if Winget is installed +function Test-WinGet { + try { + $wingetVersion = winget --version + return $true + } + catch { + Write-Host "Winget is not installed. Installation failed." -ForegroundColor Red + return $false + } +} + +# Function to install and uninstall applications +function Manage-Applications { + # Install applications from the install array + foreach ($app in $applicationsToInstall) { + try { + Write-Host "Installing $app" -ForegroundColor Yellow + winget install -e --id $app --silent --accept-source-agreements --accept-package-agreements | Out-Null + if ($LASTEXITCODE -eq 0) { + Write-Host "$app installed successfully" -ForegroundColor Green + } + else { + Write-Host "Failed to install $app" -ForegroundColor Red + } + } + catch { + Write-Host "Error installing $app $($_.Exception.Message)" -ForegroundColor Red + } + } + + # Uninstall applications from the remove array + foreach ($app in $applicationsToRemove) { + try { + Write-Host "Uninstalling $app" -ForegroundColor Yellow + winget uninstall --id $app --silent --accept-source-agreements | Out-Null + if ($LASTEXITCODE -eq 0) { + Write-Host "$app uninstalled successfully" -ForegroundColor Green + } + else { + Write-Host "Failed to uninstall $app" -ForegroundColor Red + } + } + catch { + Write-Host "Error uninstalling $app $($_.Exception.Message)" -ForegroundColor Red + } + } +} + +# Main script execution +Write-Host "Starting software management..." -ForegroundColor Cyan + +# Check if script is running as administrator +if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { + Write-Host "Script must be run as Administrator. Installation failed." -ForegroundColor Red + Exit 1 +} + +# Check if Winget is installed and proceed with installation +if (Test-WinGet) { + Manage-Applications + Write-Host "Software management completed!" -ForegroundColor Green + Exit 0 +} +else { + Exit 1 +}