mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-14 22:55:52 -06:00
* Change Main loop from 'ForEach' to 'For' inside 'Install-WinUtilProgramWinget' Private Function (#2271) * Fix Off By One Error by Replaceing Wrong Comparison Operator from '-le' (Less or Equal) to '-lt' (Less Than) in For Loop of 'Install-WinUtilProgramWinget' Private Function
This commit is contained in:
parent
f2a5574a8c
commit
fcc48a2b22
@ -22,16 +22,17 @@ Function Install-WinUtilProgramWinget {
|
|||||||
[Parameter(Position=1)]
|
[Parameter(Position=1)]
|
||||||
[String]$manage = "Installing"
|
[String]$manage = "Installing"
|
||||||
)
|
)
|
||||||
$x = 0
|
|
||||||
$count = $ProgramsToInstall.Count
|
$count = $ProgramsToInstall.Count
|
||||||
|
|
||||||
Write-Progress -Activity "$manage Applications" -Status "Starting" -PercentComplete 0
|
Write-Progress -Activity "$manage Applications" -Status "Starting" -PercentComplete 0
|
||||||
Write-Host "==========================================="
|
Write-Host "==========================================="
|
||||||
Write-Host "-- Configuring winget packages ---"
|
Write-Host "-- Configuring winget packages ---"
|
||||||
Write-Host "==========================================="
|
Write-Host "==========================================="
|
||||||
Foreach ($Program in $ProgramsToInstall){
|
for ($i = 0; $i -lt $count; $i++) {
|
||||||
|
$Program = $ProgramsToInstall[$i]
|
||||||
$failedPackages = @()
|
$failedPackages = @()
|
||||||
Write-Progress -Activity "$manage Applications" -Status "$manage $($Program.winget) $($x + 1) of $count" -PercentComplete $($x/$count*100)
|
Write-Progress -Activity "$manage Applications" -Status "$manage $($Program.winget) $($i + 1) of $count" -PercentComplete $((($i + 1)/$count) * 100)
|
||||||
if($manage -eq "Installing") {
|
if($manage -eq "Installing") {
|
||||||
# Install package via ID, if it fails try again with different scope and then with an unelevated prompt.
|
# Install package via ID, if it fails try again with different scope and then with an unelevated prompt.
|
||||||
# Since Install-WinGetPackage might not be directly available, we use winget install command as a workaround.
|
# Since Install-WinGetPackage might not be directly available, we use winget install command as a workaround.
|
||||||
@ -81,7 +82,7 @@ Function Install-WinUtilProgramWinget {
|
|||||||
$failedPackages += $Program
|
$failedPackages += $Program
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($manage -eq "Uninstalling"){
|
elseif($manage -eq "Uninstalling") {
|
||||||
# Uninstall package via ID using winget directly.
|
# Uninstall package via ID using winget directly.
|
||||||
try {
|
try {
|
||||||
$status = $(Start-Process -FilePath "winget" -ArgumentList "uninstall --id $($Program.winget) --silent" -Wait -PassThru -NoNewWindow).ExitCode
|
$status = $(Start-Process -FilePath "winget" -ArgumentList "uninstall --id $($Program.winget) --silent" -Wait -PassThru -NoNewWindow).ExitCode
|
||||||
@ -96,7 +97,9 @@ Function Install-WinUtilProgramWinget {
|
|||||||
$failedPackages += $Program
|
$failedPackages += $Program
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$X++
|
else {
|
||||||
|
throw "[Install-WinUtilProgramWinget] Invalid Value for Parameter 'manage', Provided Value is: $manage"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed
|
Write-Progress -Activity "$manage Applications" -Status "Finished" -Completed
|
||||||
return $failedPackages;
|
return $failedPackages;
|
||||||
|
Loading…
Reference in New Issue
Block a user