Actualiser powershell/Remove-BuiltInApps.ps1
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Remove selected built-in Windows apps for current and new users.
|
||||
Remove selected built-in Windows apps for current user, all existing users, and prevent them for new users.
|
||||
|
||||
.DESCRIPTION
|
||||
Removes the following apps:
|
||||
@@ -15,8 +15,10 @@
|
||||
- Weather
|
||||
- Microsoft Teams
|
||||
- OneDrive
|
||||
The script removes both the installed package for the current user
|
||||
and the provisioned package for all new users.
|
||||
The script removes:
|
||||
- Provisioned packages (prevents reinstallation for new users)
|
||||
- Packages for all existing users
|
||||
- Packages for the current user
|
||||
|
||||
.NOTES
|
||||
Must be run as Administrator
|
||||
@@ -60,6 +62,30 @@ foreach ($App in $AppsToRemove) {
|
||||
}
|
||||
}
|
||||
|
||||
# Get all user profiles except system profiles
|
||||
$UserProfiles = Get-ChildItem C:\Users | Where-Object { $_.Name -notin @("Public","Default","Default User","All Users") }
|
||||
|
||||
# Remove apps for all existing users
|
||||
Write-Host "`nRemoving apps for all existing users..." -ForegroundColor Cyan
|
||||
foreach ($UserProfile in $UserProfiles) {
|
||||
$Username = $UserProfile.Name
|
||||
Write-Host "`nProcessing user: $Username" -ForegroundColor Cyan
|
||||
|
||||
foreach ($App in $AppsToRemove) {
|
||||
try {
|
||||
$Pkg = Get-AppxPackage -User $Username -Name $App.Package
|
||||
if ($Pkg) {
|
||||
$Pkg | Remove-AppxPackage -User $Username -ErrorAction Stop
|
||||
Write-Host "✔ Removed $($App.Name) from $Username" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "$($App.Name) not installed for $Username" -ForegroundColor Yellow
|
||||
}
|
||||
} catch {
|
||||
Write-Warning "Failed to remove $($App.Name) for $Username: $_"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Remove apps for current user
|
||||
Write-Host "`nRemoving apps for current user..." -ForegroundColor Cyan
|
||||
foreach ($App in $AppsToRemove) {
|
||||
@@ -76,4 +102,4 @@ foreach ($App in $AppsToRemove) {
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "`nAll tasks completed." -ForegroundColor Cyan
|
||||
Write-Host "`nAll tasks completed for all users and provisioned packages." -ForegroundColor Cyan
|
||||
|
||||
Reference in New Issue
Block a user