119 lines
3.9 KiB
PowerShell
119 lines
3.9 KiB
PowerShell
[Console]::OutputEncoding = [Text.Encoding]::UTF8
|
|
$ErrorActionPreference = 'Continue'
|
|
|
|
Write-Host "[*] Cleaning up download shortcuts and fixing winget"
|
|
|
|
# Remove download shortcuts
|
|
$desktopPath = "C:\Users\User\Desktop"
|
|
$shortcutsToRemove = @(
|
|
"Download-Chrome.url",
|
|
"Download-7-Zip.url",
|
|
"Download-AnyDesk.url",
|
|
"Download-LINE.url",
|
|
"Download-Adobe-Reader.url",
|
|
"Installation-Instructions.txt"
|
|
)
|
|
|
|
Write-Host "[1] Removing download shortcuts..."
|
|
foreach ($shortcut in $shortcutsToRemove) {
|
|
$filePath = Join-Path $desktopPath $shortcut
|
|
if (Test-Path $filePath) {
|
|
Remove-Item $filePath -Force
|
|
Write-Host " Removed: $shortcut"
|
|
}
|
|
}
|
|
|
|
Write-Host "[2] Checking winget status..."
|
|
|
|
# Check if winget is available
|
|
try {
|
|
$wingetVersion = & winget --version 2>&1
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host " [OK] winget is available: $wingetVersion"
|
|
} else {
|
|
Write-Host " [!] winget command failed"
|
|
throw "winget not working"
|
|
}
|
|
} catch {
|
|
Write-Host " [!] winget not found or not working"
|
|
|
|
Write-Host "[3] Installing/Updating winget..."
|
|
|
|
# Method 1: Try to install App Installer (contains winget)
|
|
try {
|
|
Write-Host " Attempting to install Microsoft App Installer..."
|
|
|
|
# Download and install App Installer
|
|
$appInstallerUrl = "https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
|
|
$downloadPath = "$env:TEMP\AppInstaller.msixbundle"
|
|
|
|
Invoke-WebRequest -Uri $appInstallerUrl -OutFile $downloadPath -UseBasicParsing
|
|
|
|
# Install the package
|
|
Add-AppxPackage -Path $downloadPath
|
|
|
|
Write-Host " [OK] App Installer installed"
|
|
|
|
# Clean up
|
|
Remove-Item $downloadPath -Force -ErrorAction SilentlyContinue
|
|
|
|
} catch {
|
|
Write-Host " [!] Failed to install App Installer: $($_.Exception.Message)"
|
|
|
|
# Method 2: Try alternative approach
|
|
Write-Host " Trying alternative winget installation..."
|
|
|
|
try {
|
|
# Check Windows version and suggest manual installation
|
|
$osVersion = [System.Environment]::OSVersion.Version
|
|
Write-Host " Windows Version: $osVersion"
|
|
|
|
if ($osVersion.Major -ge 10 -and $osVersion.Build -ge 17763) {
|
|
Write-Host " [INFO] Windows version supports winget"
|
|
Write-Host " [ACTION] Manual steps required:"
|
|
Write-Host " 1. Open Microsoft Store"
|
|
Write-Host " 2. Search for 'App Installer'"
|
|
Write-Host " 3. Install/Update App Installer"
|
|
Write-Host " 4. Restart PowerShell session"
|
|
} else {
|
|
Write-Host " [!] Windows version may not support winget"
|
|
Write-Host " Consider updating Windows or using manual installation"
|
|
}
|
|
|
|
} catch {
|
|
Write-Host " [!] Could not determine Windows version"
|
|
}
|
|
}
|
|
}
|
|
|
|
Write-Host "[4] Final winget verification..."
|
|
|
|
# Wait a moment and test again
|
|
Start-Sleep -Seconds 3
|
|
|
|
try {
|
|
$wingetTest = & winget list --source winget 2>&1
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host " [OK] winget is working properly"
|
|
Write-Host " [INFO] Ready for application installation"
|
|
|
|
# Test a simple winget operation
|
|
Write-Host "[5] Testing winget functionality..."
|
|
$testResult = & winget search "7zip.7zip" 2>&1
|
|
if ($LASTEXITCODE -eq 0) {
|
|
Write-Host " [OK] winget search working"
|
|
} else {
|
|
Write-Host " [!] winget search failed, may need source configuration"
|
|
}
|
|
|
|
} else {
|
|
Write-Host " [!] winget still not working properly"
|
|
Write-Host " Output: $wingetTest"
|
|
}
|
|
} catch {
|
|
Write-Host " [!] winget verification failed: $($_.Exception.Message)"
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "Cleanup and winget setup completed!"
|
|
Write-Host "If winget is working, we can proceed with automated installation." |