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 = @(
|
$AppsToRemove = @(
|
||||||
"Microsoft.Windows.WebExperience",
|
@{Name="Windows Web Experience Pack"; Package="Microsoft.Windows.WebExperience"},
|
||||||
"Microsoft.XboxApp",
|
@{Name="Xbox"; Package="Microsoft.XboxApp"},
|
||||||
"Microsoft.OutlookApp",
|
@{Name="Outlook for Windows"; Package="Microsoft.OutlookApp"},
|
||||||
"Hub de commentaires",
|
@{Name="Feedback Hub"; Package="Microsoft.WindowsFeedbackHub"},
|
||||||
"Xbox TCUI",
|
@{Name="Xbox TCUI"; Package="Microsoft.Xbox.TCUI"},
|
||||||
"Xbox Identity Provider",
|
@{Name="Xbox Identity Provider"; Package="Microsoft.XboxIdentityProvider"},
|
||||||
"Power Automate",
|
@{Name="Power Automate"; Package="Microsoft.PowerAutomateDesktop"},
|
||||||
"Microsoft.MicrosoftStickyNotes",
|
@{Name="Sticky Notes"; Package="Microsoft.MicrosoftStickyNotes"},
|
||||||
"Microsoft.BingWeather",
|
@{Name="Weather"; Package="Microsoft.BingWeather"},
|
||||||
"Microsoft Teams",
|
@{Name="Microsoft Teams"; Package="Microsoft.Teams"},
|
||||||
"Microsoft OneDrive"
|
@{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) {
|
foreach ($App in $AppsToRemove) {
|
||||||
Write-Host "Removing provisioned package: $App"
|
try {
|
||||||
Get-AppxProvisionedPackage -Online |
|
$ProvPkg = Get-AppxProvisionedPackage -Online | Where-Object DisplayName -eq $App.Package
|
||||||
Where-Object {$_.DisplayName -eq $App} |
|
if ($ProvPkg) {
|
||||||
Remove-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue
|
$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) {
|
foreach ($App in $AppsToRemove) {
|
||||||
Write-Host "Removing app from current user: $App"
|
try {
|
||||||
Get-AppxPackage -Name $App | Remove-AppxPackage -ErrorAction SilentlyContinue
|
$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