# Requires running as administrator # Uninstalling Windows applications via winget function Initialize-Winget { if (Get-Command winget -ErrorAction SilentlyContinue) { return } Write-Host "winget not found in PATH. Attempting repair..." -ForegroundColor Yellow $MachinePath = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") $UserPath = [System.Environment]::GetEnvironmentVariable("PATH", "User") $env:PATH = $MachinePath + ";" + $UserPath if (Get-Command winget -ErrorAction SilentlyContinue) { Write-Host "winget available after PATH refresh." -ForegroundColor Green return } $AppInstaller = Get-AppxPackage -Name "Microsoft.DesktopAppInstaller" -ErrorAction SilentlyContinue if (-not $AppInstaller) { $AppInstaller = Get-AppxPackage -AllUsers -Name "Microsoft.DesktopAppInstaller" -ErrorAction SilentlyContinue } if ($AppInstaller) { Write-Host "Re-registering App Installer..." -ForegroundColor Yellow try { $Manifest = Join-Path $AppInstaller.InstallLocation "AppxManifest.xml" Add-AppxPackage -DisableDevelopmentMode -Register $Manifest -ErrorAction Stop $env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH", "User") if (Get-Command winget -ErrorAction SilentlyContinue) { Write-Host "winget repaired." -ForegroundColor Green return } } catch { Write-Warning "Re-registration failed: $_" } } $StagedPackage = Get-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue | Where-Object { $_.DisplayName -eq "Microsoft.DesktopAppInstaller" } | Select-Object -First 1 if ($StagedPackage) { Write-Host "Installing App Installer from provisioned package..." -ForegroundColor Yellow try { Add-AppxPackage -Path $StagedPackage.PackagePath -ErrorAction Stop $env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH", "User") if (Get-Command winget -ErrorAction SilentlyContinue) { Write-Host "winget installed." -ForegroundColor Green return } } catch { Write-Warning "Installation from provisioned package failed: $_" } } Write-Error ("winget is not available and could not be repaired automatically.`n" + "Install App Installer from the Microsoft Store: " + "ms-windows-store://pdp/?productid=9nblggh4nns1") exit 1 } Initialize-Winget $Packages = @( "Windows Web Experience Pack", "Xbox", "Outlook for Windows", "Hub de commentaires", "Xbox TCUI", "Xbox Identity Provider", "Power Automate", "Microsoft.MicrosoftStickyNotes", "Microsoft.BingWeather", "Microsoft Teams", "Microsoft OneDrive", "Microsoft To Do", "Microsoft Bing", "Microsoft Clipchamp", "Application Start Experiences" ) foreach ($Package in $Packages) { Write-Host "Uninstalling: $Package" -ForegroundColor Cyan winget uninstall --name "$Package" --source winget --silent --accept-source-agreements --nowarn if ($LASTEXITCODE -eq 0) { Write-Host "$Package successfully uninstalled" -ForegroundColor Green } else { Write-Warning "Failed to uninstall $Package (it may already be absent or protected)" } Write-Host "" }