forked from rgl/windows-vagrant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove-apps.ps1
88 lines (84 loc) · 3.01 KB
/
remove-apps.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
Set-StrictMode -Version Latest
$ProgressPreference = 'SilentlyContinue'
$ErrorActionPreference = 'Stop'
trap {
Write-Host
Write-Host "ERROR: $_"
($_.ScriptStackTrace -split '\r?\n') -replace '^(.*)$','ERROR: $1' | Write-Host
($_.Exception.ToString() -split '\r?\n') -replace '^(.*)$','ERROR EXCEPTION: $1' | Write-Host
Write-Host
Write-Host 'Sleeping for 60m to give you time to look around the virtual machine before self-destruction...'
Start-Sleep -Seconds (60*60)
Exit 1
}
Write-Host 'Disabling the Microsoft Consumer Experience...'
mkdir -Force 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\CloudContent' | Set-ItemProperty `
-Name DisableWindowsConsumerFeatures `
-Value 1
# when running on pwsh and windows 10, explicitly import the appx module.
# see https://github.com/PowerShell/PowerShell/issues/13138
$currentVersionKey = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
$build = [int]$currentVersionKey.CurrentBuildNumber
if (($PSVersionTable.PSEdition -ne 'Desktop') -and ($build -lt 22000)) {
Import-Module Appx -UseWindowsPowerShell
}
# remove all the provisioned appx packages.
# NB some packages fail to be removed and thats OK.
Get-AppXProvisionedPackage -Online | ForEach-Object {
Write-Host "Removing the $($_.PackageName) provisioned appx package..."
try {
$_ | Remove-AppxProvisionedPackage -Online | Out-Null
} catch {
Write-Output "WARN Failed to remove appx: $_"
}
}
# remove appx packages.
# NB some packages fail to be removed and thats OK.
# see https://docs.microsoft.com/en-us/windows/application-management/apps-in-windows-10
@(
'Microsoft.BingWeather'
'Microsoft.GetHelp'
'Microsoft.Getstarted'
'Microsoft.Microsoft3DViewer'
'Microsoft.MicrosoftOfficeHub'
'Microsoft.MicrosoftSolitaireCollection'
'Microsoft.MicrosoftStickyNotes'
'Microsoft.MixedReality.Portal'
'Microsoft.MSPaint'
'Microsoft.Office.OneNote'
'Microsoft.People'
'Microsoft.ScreenSketch'
'Microsoft.Services.Store.Engagement'
'Microsoft.SkypeApp'
'Microsoft.StorePurchaseApp'
'Microsoft.Wallet'
'Microsoft.Windows.Photos'
'Microsoft.WindowsAlarms'
'Microsoft.WindowsCalculator'
'Microsoft.WindowsCamera'
'microsoft.windowscommunicationsapps'
'Microsoft.WindowsFeedbackHub'
'Microsoft.WindowsMaps'
'Microsoft.WindowsSoundRecorder'
'Microsoft.WindowsStore'
'Microsoft.Xbox.TCUI'
'Microsoft.XboxApp'
'Microsoft.XboxGameOverlay'
'Microsoft.XboxGamingOverlay'
'Microsoft.XboxIdentityProvider'
'Microsoft.XboxSpeechToTextOverlay'
'Microsoft.YourPhone'
'Microsoft.ZuneMusic'
'Microsoft.ZuneVideo'
#'Microsoft.BioEnrollment' # NB this fails to remove.
) | ForEach-Object {
$appx = Get-AppxPackage -AllUsers $_
if ($appx) {
Write-Host "Removing the $($appx.Name) appx package..."
try {
$appx | Remove-AppxPackage -AllUsers
} catch {
Write-Output "WARN Failed to remove appx: $_"
}
}
}