-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathUninstallBuilt-InApps.ps1
More file actions
232 lines (188 loc) · 5.98 KB
/
UninstallBuilt-InApps.ps1
File metadata and controls
232 lines (188 loc) · 5.98 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<#
.SYNOPSIS
Uninstall Build-In Apps
.DESCRIPTION
This script will uninstall built-in apps in Windows 10. The script can uninstall a single app by defining it at the command line. A list of apps can be read in from a text file and iterated through for uninstallation. Finally, they can also be hardcoded into the script.
.PARAMETER AppsFile
Text file to be read in by the script which contains a list of apps to uninstall.
.PARAMETER AppName
Name of the app to uninstall. This is defined when there is only one app to uninstall.
.PARAMETER GetAppList
True or false on generating a list of Built-in apps
.PARAMETER Log
Specify true or false on whether to generate a log file in the same directory as the script containing a list of all the built-in apps by their official name
.EXAMPLE
Generate a formatted list of all installed built-in apps
powershell.exe -executionpolicy bypass -command "UninstallBuilt-InApps.ps1 -GetAppList $true
Generate a list of all installed built-in apps and write the output to a log file
powershell.exe -executionpolicy bypass -command "UninstallBuilt-InApps.ps1 -GetAppList $true -Log $true
Uninstall a single built-in app by specifying its name at the command prompt. You do need to use the official name. You can get that by generating a formatted list.
powershell.exe -executionpolicy bypass -command "UninstallBuilt-InApps.ps1" -AppName "Microsoft.WindowsCamera"
Uninstall multiple built-in apps from a list inside a text file
powershell.exe -executionpolicy bypass -command "UninstallBuilt-InApps.ps1" -AppsFile "AppsUninstall.txt
Harcode the uninstall at the bottom of this script
Uninstall-BuiltInApp -AppName "Microsoft.WindowsCamera"
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2016 v5.2.122
Created on: 6/1/2016 3:21 PM
Created by: Mick Pletcher
Filename: UninstallBuilt-InApps.ps1
===========================================================================
#>
[CmdletBinding()]
param
(
[string]
$AppsFile = $null,
[string]
$AppName = $null,
[ValidateNotNullOrEmpty()][boolean]
$GetAppList = $false,
[ValidateNotNullOrEmpty()][boolean]
$Log = $false
)
Import-Module Appx
function Get-AppName {
<#
.SYNOPSIS
Format App name
.DESCRIPTION
This will format a built-in app name for proper display
.PARAMETER Name
Name of the application
.EXAMPLE
PS C:\> Get-AppName -Name 'Value1'
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()]
$Name
)
$Temp = $Name.Split('.')
For ($j = 0; $j -lt $Temp.Count; $j++) {
$Numeric = [bool]($Temp[$j] -as [double])
If ($Temp[$j] -eq 'Net') {
$Temp[$j] = "." + $Temp[$j]
}
If ($Numeric -eq $true) {
If ($Temp[$j + 1] -ne $null) {
$Temp[$j] = $Temp[$j] + '.'
}
$FormattedName = $FormattedName + $Temp[$j]
} else {
$FormattedName = $FormattedName + $Temp[$j] + [char]32
}
}
Return $FormattedName
}
function Get-BuiltInAppsList {
<#
.SYNOPSIS
List all Built-In Apps
.DESCRIPTION
Query for a list of all Build-In Apps
.EXAMPLE
PS C:\> Get-BuiltInAppsList
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param ()
$Apps = Get-AppxPackage
$Apps = $Apps.Name
$Apps = $Apps | Sort-Object
If ($Log -eq $true) {
$RelativePath = Get-RelativePath
$Apps | Out-File -FilePath $RelativePath"AllAppslist.txt" -Encoding UTF8
}
For ($i = 0; $i -lt $Apps.count; $i++) {
$Temp = Get-AppName -Name $Apps[$i]
$Apps[$i] = $Temp
}
$Apps
}
function Get-RelativePath {
<#
.SYNOPSIS
Get the relative path of the PowerShell script
.DESCRIPTION
Returns the path location of the PowerShell script being executed
.EXAMPLE
PS C:\> Get-RelativePath
.NOTES
Additional information about the function.
#>
[CmdletBinding()][OutputType([string])]
param ()
$RelativePath = (split-path $SCRIPT:MyInvocation.MyCommand.Path -parent) + "\"
Return $RelativePath
}
function Uninstall-BuiltInApp {
<#
.SYNOPSIS
Uninstall Windows 10 Built In App
.DESCRIPTION
This will uninstall a built-in app by passing the name of the app in.
.PARAMETER AppName
Name of the App
.EXAMPLE
PS C:\> Uninstall-BuiltInApp -AppName 'Value1'
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string]
$AppName
)
$App = Get-AppName -Name $AppName
Write-Host "Uninstalling"$App"....." -NoNewline
$Output = Get-AppxPackage $AppName
If ($Output -eq $null) {
Write-Host "Not Installed" -ForegroundColor Yellow
} else {
$Output = Get-AppxPackage $AppName | Remove-AppxPackage
$Output = Get-AppxPackage $AppName
If ($Output -eq $null) {
Write-Host "Success" -ForegroundColor Yellow
} else {
Write-Host "Failed" -ForegroundColor Red
}
}
}
function Uninstall-BuiltInApps {
<#
.SYNOPSIS
Uninstall Windows 10 Built In Apps
.DESCRIPTION
This will uninstall a list of built-in apps by reading the app names from a text file located in the same directory as this script.
.NOTES
Additional information about the function.
#>
[CmdletBinding()]
param ()
$RelativePath = Get-RelativePath
$AppsFile = $RelativePath + $AppsFile
$List = Get-Content -Path $AppsFile
foreach ($App in $List) {
Uninstall-BuiltInApp -AppName $App
}
}
cls
#Generate list of all Build-In apps
If ($GetAppList -eq $true) {
Get-BuiltInAppsList
}
#Uninstall a single app
If (($AppName -ne $null) -and ($AppName -ne "")) {
Uninstall-BuiltInApp -AppName $AppName
}
#Read list of apps to uninstall from text file and uninstall all on the list
If (($GetAppList -ne $null) -and ($GetAppList -ne "")) {
Uninstall-BuiltInApps
}