Actualiser powershell/Remove-BuiltInApps.ps1
This commit is contained in:
@@ -1,28 +1,79 @@
|
||||
# Run as Administrator
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Remove selected built-in Windows apps for current and new users.
|
||||
|
||||
.DESCRIPTION
|
||||
Removes the following apps:
|
||||
- Windows Web Experience Pack
|
||||
- Xbox
|
||||
- Outlook for Windows
|
||||
- Feedback Hub
|
||||
- Xbox TCUI
|
||||
- Xbox Identity Provider
|
||||
- Power Automate
|
||||
- Sticky Notes
|
||||
- Weather
|
||||
- Microsoft Teams
|
||||
- OneDrive
|
||||
The script removes both the installed package for the current user
|
||||
and the provisioned package for all new users.
|
||||
|
||||
.NOTES
|
||||
Must be run as Administrator
|
||||
#>
|
||||
|
||||
# Check for Admin
|
||||
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
|
||||
{
|
||||
Write-Error "This script must be run as Administrator."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# List of apps to remove
|
||||
$AppsToRemove = @(
|
||||
"Microsoft.Windows.WebExperience",
|
||||
"Microsoft.XboxApp",
|
||||
"Microsoft.OutlookApp",
|
||||
"Hub de commentaires",
|
||||
"Xbox TCUI",
|
||||
"Xbox Identity Provider",
|
||||
"Power Automate",
|
||||
"Microsoft.MicrosoftStickyNotes",
|
||||
"Microsoft.BingWeather",
|
||||
"Microsoft Teams",
|
||||
"Microsoft OneDrive"
|
||||
@{Name="Windows Web Experience Pack"; Package="Microsoft.Windows.WebExperience"},
|
||||
@{Name="Xbox"; Package="Microsoft.XboxApp"},
|
||||
@{Name="Outlook for Windows"; Package="Microsoft.OutlookApp"},
|
||||
@{Name="Feedback Hub"; Package="Microsoft.WindowsFeedbackHub"},
|
||||
@{Name="Xbox TCUI"; Package="Microsoft.Xbox.TCUI"},
|
||||
@{Name="Xbox Identity Provider"; Package="Microsoft.XboxIdentityProvider"},
|
||||
@{Name="Power Automate"; Package="Microsoft.PowerAutomateDesktop"},
|
||||
@{Name="Sticky Notes"; Package="Microsoft.MicrosoftStickyNotes"},
|
||||
@{Name="Weather"; Package="Microsoft.BingWeather"},
|
||||
@{Name="Microsoft Teams"; Package="Microsoft.Teams"},
|
||||
@{Name="OneDrive"; Package="Microsoft.OneDrive")
|
||||
)
|
||||
|
||||
# Remove provisioned packages for new users
|
||||
# Remove provisioned packages (prevents reinstallation for new users)
|
||||
Write-Host "Removing provisioned packages for new users..." -ForegroundColor Cyan
|
||||
foreach ($App in $AppsToRemove) {
|
||||
Write-Host "Removing provisioned package: $App"
|
||||
Get-AppxProvisionedPackage -Online |
|
||||
Where-Object {$_.DisplayName -eq $App} |
|
||||
Remove-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue
|
||||
try {
|
||||
$ProvPkg = Get-AppxProvisionedPackage -Online | Where-Object DisplayName -eq $App.Package
|
||||
if ($ProvPkg) {
|
||||
$ProvPkg | Remove-AppxProvisionedPackage -Online -ErrorAction Stop
|
||||
Write-Host "✔ Provisioned package removed: $($App.Name)" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "No provisioned package found for $($App.Name)" -ForegroundColor Yellow
|
||||
}
|
||||
} catch {
|
||||
Write-Warning "Failed to remove provisioned package for $($App.Name): $_"
|
||||
}
|
||||
}
|
||||
|
||||
# Remove for current user
|
||||
# Remove apps for current user
|
||||
Write-Host "`nRemoving apps for current user..." -ForegroundColor Cyan
|
||||
foreach ($App in $AppsToRemove) {
|
||||
Write-Host "Removing app from current user: $App"
|
||||
Get-AppxPackage -Name $App | Remove-AppxPackage -ErrorAction SilentlyContinue
|
||||
try {
|
||||
$UserPkg = Get-AppxPackage -Name $App.Package
|
||||
if ($UserPkg) {
|
||||
$UserPkg | Remove-AppxPackage -ErrorAction Stop
|
||||
Write-Host "✔ Removed $($App.Name) from current user" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "$($App.Name) is not installed for current user" -ForegroundColor Yellow
|
||||
}
|
||||
} catch {
|
||||
Write-Warning "Failed to remove $($App.Name) for current user: $_"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "`nAll tasks completed." -ForegroundColor Cyan
|
||||
Reference in New Issue
Block a user