Skip to content

Instantly share code, notes, and snippets.

@Axlfc
Created October 23, 2024 07:06
Show Gist options
  • Save Axlfc/a338bc1ad863ad26df17d39ddcb84591 to your computer and use it in GitHub Desktop.
Save Axlfc/a338bc1ad863ad26df17d39ddcb84591 to your computer and use it in GitHub Desktop.
param (
# Define a parameter for the folder path
[Parameter(Mandatory=$true)]
[string]$folderPath
)
try {
# Verify the path exists
if (-Not (Test-Path $folderPath)) {
Write-Error "The provided path does not exist or is not accessible. Please provide a valid path."
exit
}
# Ask for administrative credentials
$credential = Get-Credential -Message "Please enter admin credentials to install software"
# Get all .exe files in the folder
$exeFiles = Get-ChildItem -Path $folderPath -Filter "*.exe"
# Check if .exe files are found
if ($exeFiles.Count -eq 0) {
Write-Error "No .exe files found in the specified folder."
exit
}
$totalFiles = $exeFiles.Count
$counter = 0
foreach ($exeFile in $exeFiles) {
$counter++
# Define progress details
$progressParams = @{
Activity = "Installing $($exeFile.Name)"
Status = "File $counter of $totalFiles"
PercentComplete = ($counter / $totalFiles) * 100
}
# Show progress bar
Write-Progress @progressParams
# Start the installation process
$processArgs = @{
FilePath = $exeFile.FullName
Credential = $credential
ArgumentList = '/S' # Use '/S' for silent installation if supported
Wait = $true
NoNewWindow = $true # Run the process in the current PowerShell window
}
Start-Process @processArgs
}
# Complete progress bar
Write-Progress -Activity "Installation Complete" -Status "All files installed" -Completed
} catch {
Write-Error $_.Exception.Message
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment