fix fout-code
This commit is contained in:
1 parent
2f96eee4ad
commit
d77a198dc0
1 file changed
+30
-46
+30
-46
@@ -321,33 +321,25 @@ function Install-MedewerkersApps {
|
||||
Write-ColorText "[$currentApp/$totalApps] Installeer $app..." "Cyan"
|
||||
|
||||
try {
|
||||
# Capture both output and error streams
|
||||
$outputFile = "$env:TEMP\winget_$(Get-Random).txt"
|
||||
$errorFile = "$env:TEMP\winget_error_$(Get-Random).txt"
|
||||
# Capture output using Invoke-Expression to properly capture stdout
|
||||
$output = & winget install --id $app -e --silent --accept-package-agreements --accept-source-agreements --source winget --scope machine 2>&1
|
||||
$exitCode = $LASTEXITCODE
|
||||
$outputString = $output | Out-String
|
||||
|
||||
$process = Start-Process -NoNewWindow -Wait -FilePath "winget" -ArgumentList "install --id $app -e --silent --accept-package-agreements --accept-source-agreements --source winget --scope machine" -PassThru -RedirectStandardOutput $outputFile -RedirectStandardError $errorFile
|
||||
$exitCode = $process.ExitCode
|
||||
|
||||
# Read output to determine actual result
|
||||
$outputContent = ""
|
||||
$errorContent = ""
|
||||
if (Test-Path $outputFile) {
|
||||
$outputContent = Get-Content $outputFile -Raw -ErrorAction SilentlyContinue
|
||||
Remove-Item $outputFile -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
if (Test-Path $errorFile) {
|
||||
$errorContent = Get-Content $errorFile -Raw -ErrorAction SilentlyContinue
|
||||
Remove-Item $errorFile -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
# Check for success indicators in output
|
||||
$combinedOutput = "$outputContent $errorContent"
|
||||
if ($combinedOutput -match "Successfully installed" -or $exitCode -eq 0) {
|
||||
# Determine result based on output content and exit code
|
||||
if ($exitCode -eq 0 -or $outputString -match "Successfully installed|Successfully verified") {
|
||||
Write-ColorText "✓ $app succesvol geïnstalleerd" "Green"
|
||||
} elseif ($combinedOutput -match "already installed|No applicable|No available upgrade" -or ($null -ne $exitCode -and $exitCode -ne 0)) {
|
||||
} elseif ($outputString -match "already installed|existing package|No applicable upgrade|No available upgrade|Found an existing package|Trying to upgrade") {
|
||||
Write-ColorText "✓ $app is al geïnstalleerd (geen actie nodig)" "Yellow"
|
||||
} elseif ($outputString -match "No upgrade available|No newer package versions") {
|
||||
Write-ColorText "✓ $app is al geïnstalleerd (geen actie nodig)" "Yellow"
|
||||
} else {
|
||||
Write-ColorText "✗ Fout bij installatie van $app" "Red"
|
||||
# Show error with exit code for debugging
|
||||
Write-ColorText "✗ Fout bij installatie van $app (Exit code: $exitCode)" "Red"
|
||||
if ($outputString) {
|
||||
$shortOutput = $outputString.Substring(0, [Math]::Min(200, $outputString.Length))
|
||||
Write-ColorText " Output: $shortOutput..." "Gray"
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
Write-ColorText "✗ Fout bij installatie van $app" "Red"
|
||||
@@ -424,33 +416,25 @@ function Install-GastenApps {
|
||||
Write-ColorText "[$currentApp/$totalApps] Installeer $app..." "Cyan"
|
||||
|
||||
try {
|
||||
# Capture both output and error streams
|
||||
$outputFile = "$env:TEMP\winget_$(Get-Random).txt"
|
||||
$errorFile = "$env:TEMP\winget_error_$(Get-Random).txt"
|
||||
# Capture output using Invoke-Expression to properly capture stdout
|
||||
$output = & winget install --id $app -e --silent --accept-package-agreements --accept-source-agreements --source winget --scope machine 2>&1
|
||||
$exitCode = $LASTEXITCODE
|
||||
$outputString = $output | Out-String
|
||||
|
||||
$process = Start-Process -NoNewWindow -Wait -FilePath "winget" -ArgumentList "install --id $app -e --silent --accept-package-agreements --accept-source-agreements --source winget --scope machine" -PassThru -RedirectStandardOutput $outputFile -RedirectStandardError $errorFile
|
||||
$exitCode = $process.ExitCode
|
||||
|
||||
# Read output to determine actual result
|
||||
$outputContent = ""
|
||||
$errorContent = ""
|
||||
if (Test-Path $outputFile) {
|
||||
$outputContent = Get-Content $outputFile -Raw -ErrorAction SilentlyContinue
|
||||
Remove-Item $outputFile -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
if (Test-Path $errorFile) {
|
||||
$errorContent = Get-Content $errorFile -Raw -ErrorAction SilentlyContinue
|
||||
Remove-Item $errorFile -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
# Check for success indicators in output
|
||||
$combinedOutput = "$outputContent $errorContent"
|
||||
if ($combinedOutput -match "Successfully installed" -or $exitCode -eq 0) {
|
||||
# Determine result based on output content and exit code
|
||||
if ($exitCode -eq 0 -or $outputString -match "Successfully installed|Successfully verified") {
|
||||
Write-ColorText "✓ $app succesvol geïnstalleerd" "Green"
|
||||
} elseif ($combinedOutput -match "already installed|No applicable|No available upgrade" -or ($null -ne $exitCode -and $exitCode -ne 0)) {
|
||||
} elseif ($outputString -match "already installed|existing package|No applicable upgrade|No available upgrade|Found an existing package|Trying to upgrade") {
|
||||
Write-ColorText "✓ $app is al geïnstalleerd (geen actie nodig)" "Yellow"
|
||||
} elseif ($outputString -match "No upgrade available|No newer package versions") {
|
||||
Write-ColorText "✓ $app is al geïnstalleerd (geen actie nodig)" "Yellow"
|
||||
} else {
|
||||
Write-ColorText "✗ Fout bij installatie van $app" "Red"
|
||||
# Show error with exit code for debugging
|
||||
Write-ColorText "✗ Fout bij installatie van $app (Exit code: $exitCode)" "Red"
|
||||
if ($outputString) {
|
||||
$shortOutput = $outputString.Substring(0, [Math]::Min(200, $outputString.Length))
|
||||
Write-ColorText " Output: $shortOutput..." "Gray"
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
Write-ColorText "✗ Fout bij installatie van $app" "Red"
|
||||
|
||||
Reference in new issue
Block a user