fix syntax

This commit is contained in:
Chris Titus
2024-05-09 17:20:27 -07:00
parent ea60dac8dd
commit db0024b7c5
2 changed files with 29 additions and 20 deletions

1
.gitignore vendored
View File

@ -44,3 +44,4 @@ Microsoft.PowerShell.ConsoleHost.dll
microwin.log microwin.log
True True
test.ps1 test.ps1
winutil.ps1

View File

@ -26,32 +26,40 @@ Function Install-WinUtilProgramWinget {
Foreach ($Program in $($ProgramsToInstall -split ",")){ Foreach ($Program in $($ProgramsToInstall -split ",")){
Write-Progres -Activity "$manage Applications" -Status "$manage $Program $($x + 1) of $count" -PercentComplete $($x/$count*100) Write-Progress -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 -eq 0){ if($status -eq 0){
write-host "$program installed successfully." Write-Host "$Program installed successfully."
continue continue
} }
Write-Host "Attempt with User scope" Write-Host "Attempt with User scope"
$status = $(Start-Process -FilePath "winget" -ArgumentList "install --id $Program --scope user --silent --accept-source-agreements --accept-package-agreements" -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 -eq 0){ if($status -eq 0){
Write-Host "$Program installed successfully with User scope." Write-Host "$Program installed successfully with User scope."
continue continue
} }
Write-Host "Attempt with Unelevated prompt" Write-Host "Attempt with Unelevated prompt"
$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 $process = Start-Process -FilePath "powershell" -ArgumentList "-Command Start-Process winget -ArgumentList 'install --id $Program --silent --accept-source-agreements --accept-package-agreements' -Verb runAsUser" -Wait -PassThru
if(status -eq 0){ if($process.ExitCode -eq 0){
Write-Host "$Program installed successfully with Unelevated prompt." Write-Host "$Program installed successfully with Unelevated prompt."
continue continue
} }
Write-Host "Failed to install $Program." Write-Host "Attempting installation with Chocolatey as a fallback method"
} catch { $chocoStatus = $(Start-Process -FilePath "choco" -ArgumentList "install $Program -y" -Wait -PassThru).ExitCode
if($chocoStatus -eq 0){
Write-Host "$Program installed successfully using Chocolatey."
continue
} else {
Write-Host "Failed to install $Program using Chocolatey."
}
Write-Host "Failed to install $Program."
} catch {
Write-Host "Failed to install $Program due to an error: $_" Write-Host "Failed to install $Program due to an error: $_"
} }
} }