Created
October 23, 2024 07:06
-
-
Save Axlfc/a338bc1ad863ad26df17d39ddcb84591 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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