mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2025-07-06 05:03:52 -05:00
fix nested ifs
This commit is contained in:
@ -26,34 +26,34 @@ Function Install-WinUtilProgramWinget {
|
|||||||
|
|
||||||
Foreach ($Program in $($ProgramsToInstall -split ",")){
|
Foreach ($Program in $($ProgramsToInstall -split ",")){
|
||||||
|
|
||||||
Write-Progress -Activity "$manage Applications" -Status "$manage $Program $($x + 1) of $count" -PercentComplete $($x/$count*100)
|
Write-Progres -Activity "$manage Applications" -Status "$manage $Program $($x + 1) of $count" -PercentComplete $($x/$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.
|
||||||
# Winget, not all installers honor any of the following: System-wide, User Installs, or Unelevated Prompt OR Silent Install Mode.
|
# Winget, not all installers honor any of the following: System-wide, User Installs, or Unelevated Prompt OR Silent Install Mode.
|
||||||
# This is up to the individual package maintainers to enable these options. Aka. not as clean as Linux Package Managers.
|
# This is up to the individual package maintainers to enable these options. Aka. not as clean as Linux Package Managers.
|
||||||
try {
|
try {
|
||||||
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $Program --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru).ExitCode
|
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $Program --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru).ExitCode
|
||||||
if($status -ne 0){
|
if(status -eq 0){
|
||||||
Write-Host "Attempt with User scope"
|
write-host "$program installed successfully."
|
||||||
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $Program --scope user --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru).ExitCode
|
continue
|
||||||
if($status -ne 0){
|
}
|
||||||
Write-Host "Attempt with Unelevated prompt"
|
Write-Host "Attempt with User scope"
|
||||||
$status = $(Start-Process -FilePath "powershell" -ArgumentList "-Command Start-Process winget -ArgumentList 'install --id $Program --silent --accept-source-agreements --accept-package-agreements' -Verb runAsUser" -Wait -PassThru).ExitCode
|
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $Program --scope user --silent --accept-source-agreements --accept-package-agreements" -Wait -PassThru).ExitCode
|
||||||
if($status -ne 0){
|
if(status -eq 0){
|
||||||
Write-Host "Failed to install $Program."
|
Write-Host "$Program installed successfully with User scope."
|
||||||
} else {
|
continue
|
||||||
Write-Host "$Program installed successfully with Unelevated prompt."
|
}
|
||||||
}
|
Write-Host "Attempt with Unelevated prompt"
|
||||||
} else {
|
$status = $(Start-Process -FilePath "powershell" -ArgumentList "-Command Start-Process winget -ArgumentList 'install --id $Program --silent --accept-source-agreements --accept-package-agreements' -Verb runAsUser" -Wait -PassThru).ExitCode
|
||||||
Write-Host "$Program installed successfully with User scope."
|
if(status -eq 0){
|
||||||
}
|
Write-Host "$Program installed successfully with Unelevated prompt."
|
||||||
} else {
|
continue
|
||||||
Write-Host "$Program installed successfully."
|
}
|
||||||
}
|
Write-Host "Failed to install $Program."
|
||||||
} catch {
|
} catch {
|
||||||
Write-Host "Failed to install $Program due to an error: $_"
|
Write-Host "Failed to install $Program due to an error: $_"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($manage -eq "Uninstalling"){
|
if($manage -eq "Uninstalling"){
|
||||||
# Uninstall package via ID using winget directly.
|
# Uninstall package via ID using winget directly.
|
||||||
|
Reference in New Issue
Block a user