Fix: pass -RunAsAdmin to Scoop installer when running as Administrator (Server 2022)

This commit is contained in:
2026-05-04 14:16:34 +02:00
parent 3357e67865
commit 18ff5a96c3

View File

@ -44,37 +44,45 @@ if ($policy -in @('Bypass', 'Unrestricted', 'RemoteSigned')) {
# Hilfsfunktion: Scoop-Installer herunterladen und ausfuehren # Hilfsfunktion: Scoop-Installer herunterladen und ausfuehren
function Install-Scoop { function Install-Scoop {
$url = 'https://get.scoop.sh' $url = 'https://get.scoop.sh'
$tmp = "$env:TEMP\scoop-install.ps1"
# Versuch 1: Invoke-RestMethod # Scoop verweigert Installation als Admin ohne explizites Flag
try { # Loesung: Installer-Script laden und mit -RunAsAdmin aufrufen
Invoke-RestMethod -Uri $url | Invoke-Expression $runAsAdmin = $isAdmin
return $true
} catch {}
# Versuch 2: WebClient # Hilfsfunktion: Script-Inhalt herunterladen mit SSL-Bypass-Fallback
try { function Get-InstallerScript($url) {
(New-Object System.Net.WebClient).DownloadString($url) | Invoke-Expression try { return Invoke-RestMethod -Uri $url } catch {}
return $true try { return (New-Object System.Net.WebClient).DownloadString($url) } catch {}
} catch {} # SSL-Bypass (Server 2016 fehlende Zertifikatskette)
Write-Host " SSL-Bypass aktiv (Server 2016/2022 Zertifikatskette)..."
$cb = [Net.ServicePointManager]::ServerCertificateValidationCallback
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
try { return (New-Object System.Net.WebClient).DownloadString($url) }
catch {
Write-Host "FEHLER: Scoop-Download fehlgeschlagen: $_"
Write-Host " - Windows Update ausfuehren (fehlende Root-Zertifikate)"
Write-Host " - Proxy auf HTTPS-Durchlass pruefen"
return $null
} finally {
[Net.ServicePointManager]::ServerCertificateValidationCallback = $cb
}
}
$script = Get-InstallerScript $url
if (-not $script) { return $false }
# Versuch 3: WebClient mit SSL-Bypass (Windows Server 2016 fehlende Zertifikatskette)
Write-Host " Versuche SSL-Bypass fuer Scoop-Download (Server 2016)..."
$prevCb = [Net.ServicePointManager]::ServerCertificateValidationCallback
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
try { try {
(New-Object System.Net.WebClient).DownloadString($url) | Invoke-Expression $sb = [scriptblock]::Create($script)
if ($runAsAdmin) {
# -RunAsAdmin ueberschreibt Scoop-Sperre fuer Administrator-Konten
& $sb -RunAsAdmin
} else {
& $sb
}
return $true return $true
} catch { } catch {
Write-Host "FEHLER: Scoop-Download fehlgeschlagen: $_" Write-Host "FEHLER: Scoop-Installation fehlgeschlagen: $_"
Write-Host ""
Write-Host "Moegliche Ursachen auf Windows Server 2016:"
Write-Host " - Fehlende Root-Zertifikate (Windows Update ausfuehren)"
Write-Host " - Proxy blockiert HTTPS"
Write-Host " - get.scoop.sh nicht erreichbar"
return $false return $false
} finally {
[Net.ServicePointManager]::ServerCertificateValidationCallback = $prevCb
} }
} }