148 lines
4.8 KiB
PowerShell
148 lines
4.8 KiB
PowerShell
# Requires running as administrator
|
|
# Removes selected built-in Appx packages without winget.
|
|
# Installed packages are removed for existing users when supported.
|
|
# Provisioned packages are removed so they are not installed for new users.
|
|
|
|
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = "High")]
|
|
param(
|
|
[switch]$IncludeOneDrive
|
|
)
|
|
|
|
$ErrorActionPreference = "Continue"
|
|
|
|
$IsAdministrator = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
|
|
[Security.Principal.WindowsBuiltInRole]::Administrator
|
|
)
|
|
|
|
if (-not $IsAdministrator) {
|
|
Write-Error "This script must be run from an administrator PowerShell session."
|
|
exit 1
|
|
}
|
|
|
|
$PackageNamePatterns = @(
|
|
"MicrosoftWindows.Client.WebExperience",
|
|
"Microsoft.OutlookForWindows",
|
|
"Microsoft.WindowsFeedbackHub",
|
|
"Microsoft.XboxApp",
|
|
"Microsoft.GamingApp",
|
|
"Microsoft.Xbox.TCUI",
|
|
"Microsoft.XboxGameOverlay",
|
|
"Microsoft.XboxGamingOverlay",
|
|
"Microsoft.XboxIdentityProvider",
|
|
"Microsoft.XboxSpeechToTextOverlay",
|
|
"Microsoft.PowerAutomateDesktop",
|
|
"Microsoft.MicrosoftStickyNotes",
|
|
"Microsoft.BingWeather",
|
|
"MSTeams",
|
|
"MicrosoftTeams",
|
|
"Microsoft.Todos",
|
|
"Microsoft.BingSearch",
|
|
"Microsoft.BingNews",
|
|
"Clipchamp.Clipchamp"
|
|
)
|
|
|
|
function Invoke-InstalledAppxPackageRemoval {
|
|
param(
|
|
[string]$Pattern
|
|
)
|
|
|
|
$Packages = Get-AppxPackage -AllUsers -Name $Pattern -ErrorAction SilentlyContinue
|
|
|
|
if (-not $Packages) {
|
|
Write-Host "No installed Appx package found for: $Pattern" -ForegroundColor DarkGray
|
|
return
|
|
}
|
|
|
|
foreach ($Package in $Packages) {
|
|
$Target = "$($Package.Name) [$($Package.PackageFullName)]"
|
|
Write-Host "Removing installed package: $Target" -ForegroundColor Cyan
|
|
|
|
if ($PSCmdlet.ShouldProcess($Target, "Remove installed Appx package")) {
|
|
try {
|
|
Remove-AppxPackage -Package $Package.PackageFullName -AllUsers -ErrorAction Stop
|
|
Write-Host "Removed installed package: $($Package.Name)" -ForegroundColor Green
|
|
}
|
|
catch {
|
|
Write-Warning "Failed to remove installed package $($Package.Name): $_"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function Invoke-ProvisionedAppxPackageRemoval {
|
|
param(
|
|
[string]$Pattern
|
|
)
|
|
|
|
$ProvisionedPackages = Get-AppxProvisionedPackage -Online |
|
|
Where-Object {
|
|
$_.DisplayName -like $Pattern -or
|
|
$_.PackageName -like "$Pattern*"
|
|
}
|
|
|
|
if (-not $ProvisionedPackages) {
|
|
Write-Host "No provisioned Appx package found for: $Pattern" -ForegroundColor DarkGray
|
|
return
|
|
}
|
|
|
|
foreach ($Package in $ProvisionedPackages) {
|
|
$Target = "$($Package.DisplayName) [$($Package.PackageName)]"
|
|
Write-Host "Removing provisioned package: $Target" -ForegroundColor Cyan
|
|
|
|
if ($PSCmdlet.ShouldProcess($Target, "Remove provisioned Appx package for future users")) {
|
|
try {
|
|
Remove-AppxProvisionedPackage -Online -PackageName $Package.PackageName -ErrorAction Stop | Out-Null
|
|
Write-Host "Removed provisioned package: $($Package.DisplayName)" -ForegroundColor Green
|
|
}
|
|
catch {
|
|
Write-Warning "Failed to remove provisioned package $($Package.DisplayName): $_"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function Invoke-OneDriveRemoval {
|
|
$Installers = @(
|
|
"$env:SystemRoot\System32\OneDriveSetup.exe",
|
|
"$env:SystemRoot\SysWOW64\OneDriveSetup.exe"
|
|
)
|
|
|
|
foreach ($Installer in $Installers) {
|
|
if (-not (Test-Path $Installer)) {
|
|
continue
|
|
}
|
|
|
|
Write-Host "Removing OneDrive with: $Installer" -ForegroundColor Cyan
|
|
|
|
if ($PSCmdlet.ShouldProcess($Installer, "Uninstall OneDrive")) {
|
|
try {
|
|
Start-Process -FilePath $Installer -ArgumentList "/uninstall" -Wait -NoNewWindow
|
|
Write-Host "OneDrive uninstall command completed." -ForegroundColor Green
|
|
}
|
|
catch {
|
|
Write-Warning "Failed to uninstall OneDrive with $Installer`: $_"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Write-Host "Removing selected built-in Appx applications..." -ForegroundColor Cyan
|
|
Write-Host "This can affect existing users and the default package set for new users." -ForegroundColor Yellow
|
|
Write-Host ""
|
|
|
|
foreach ($Pattern in $PackageNamePatterns) {
|
|
Invoke-InstalledAppxPackageRemoval -Pattern $Pattern
|
|
Invoke-ProvisionedAppxPackageRemoval -Pattern $Pattern
|
|
Write-Host ""
|
|
}
|
|
|
|
if ($IncludeOneDrive) {
|
|
Invoke-OneDriveRemoval
|
|
}
|
|
else {
|
|
Write-Host "OneDrive was not removed. Re-run with -IncludeOneDrive to call the built-in OneDrive uninstaller." -ForegroundColor Yellow
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "Done. Restart Windows before creating new user profiles." -ForegroundColor Green
|