Repository navigation
Expand file tree
/
Copy pathDelete-Apps.ps1
More file actions
255 lines (212 loc) · 9.79 KB
/
Copy pathDelete-Apps.ps1
File metadata and controls
255 lines (212 loc) · 9.79 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<#
.SYNOPSIS
Delete-Apps.ps1 - PowerShell script to detect Windows Apps and delete/installs it.
.DESCRIPTION
This PowerShell script will try to get the AppxPackage and delete or install the application
on your Windows 8, Windows 8.1 or Windows 10 device. You will need to execute on some devices
the following PowerShell command: "Set-ExecutionPolicy RemoteSigned" - this will ensure you
have enough privileges to delete those apps. Also you have the ability to delete system Apps,
where we don't have in our Database.ps1 - Support us and send us your list of Apps:
"Get-AppxPackage | Select Name" in PowerShell and send us the output or you can directly save
in a text file with the following command:
"Get-AppxPackage | Select Name >> $env:userprofile\Desktop\Windows-Apps_$(gc env:computername).txt"
.EXAMPLE
.\Delete-Apps.ps1
.OUTPUT
NONE
.PARAMETER LANG CODE (2 Letter ISO Code)
You can also switch the language by .\Delete-Apps.ps1 DE (for German)
Currently supported languages DE,FR,EN
.NOTES
Written by Sascha Sebastian Helfinger - sascha.sebastian.helfinger@shelfinger.com, sh@shelfinger.eu
Technical Consultant/Director at SHelfinger Sarl - https://shelfinger.eu, http://shelfinger.com
You can also find me on:
* Twitter: https://twitter.com/shelfinger
* LinkedIn: http://tg.linkedin.com/in/shelfinger/
* Github: https://github.com/shelfinger
* Facebook: https://facebook.com/SHelfinger.EU
License:
The MIT License (MIT)
Copyright (c) 2016 Sascha Sebastian Helfinger
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Change Log:
V1.00, 31/05/2016 - First release
V1.01, 02/06/2016 - Database updatable function included
V1.02, 03/06/2016 - Language (DE, FR, EN) and updatable function included
V1.03, 04/06/2016 - Added the Global Package delete function
V1.04, 27/07/2016 - Bug from "Updating the Database" when it's older than 7 days
#>
[CmdletBinding()]
Param (
[parameter(ValueFromPipeline=$True)]
[string[]]$language
)
$ComputerName = $(gc env:computername)
$Logfile = "$PSScriptRoot\$ComputerName.log"
$database_file = "$PSScriptRoot\Database.ps1"
$WindowsSupported = 0
$PowerShellMinimumVersion = "2.0.0"
$PowerShellVersion = $PSVersionTable.PSVersion
$ScriptVersion = "1.03"
Function LogWrite {
Param ([string] $logstring)
$date = Get-Date -format G
Add-content $Logfile -value "$date - $logstring"
}
Function Get-Database {
$url = "https://shelfinger.eu/development/windows/Delete-Apps/Database.ps1"
$output = "$PSScriptRoot\Database.ps1"
Start-BitsTransfer -Source $url -Destination $output
return
}
Function Get-OSVersion {
$signature = @"
[DllImport("kernel32.dll")]
public static extern uint GetVersion();
"@
Add-Type -MemberDefinition $signature -Name "Win32OSVersion" -Namespace Win32Functions -PassThru
}
$OSVersion = [System.BitConverter]::GetBytes((Get-OSVersion)::GetVersion())
$OSString = $OSVersion[0], $OSVersion[1]
if ($language) { $Lang = $language }
else {
$tmp = Get-Culture
$Lang = $tmp.TwoLetterISOLanguageName
}
if(![System.IO.File]::Exists($database_file)){
LogWrite "================= Downloading Database ================="
LogWrite "Database not found, downloading new Database."
Get-Database
. $database_file
LogWrite "Downloaded the Database and can be found now in $database_file"
} else {
LogWrite "================= Checking Database ================="
$lastWrite = (get-item $database_file).LastWriteTime
$timespan = new-timespan -days 7
if (((get-date) - $lastWrite) -gt $timespan) {
LogWrite "File is: $(((get-date) - $lastWrite).TotalDays) days old."
Remove-Item $database_file
Get-Database
. $database_file
} else {
LogWrite "Database file found and not older than 7 days."
. $database_file
}
}
Foreach ($v in $versions) {
if ($v[2] -eq $OSString) {
$gversionn = $v[0]
$gversionm = $v[1]
$gversioni = $v[2]
$WindowsSupported = 1
}
}
if ([version]$PowerShellVersion -lt [version]$PowerShellMinimumVersion) {
$WindowsSupported = 1
}
if ($WindowsSupported -eq 0) {
Write-Host "Your Windows Version ($OSVersion) is currently not supported from this PowerShell Script."
Write-Host "- Please check that you have the latest Database.ps1 file in your Script dir ($PSScriptRoot) with Version ($DatabaseVersion)"
Write-Host "- Please check that your PowerShell Version is upper than V$PowerShellMinimumVersion (V$PowerShellVersion)"
Write-Host "- Also visit https://shelfinger.eu for a newer version of Delete-Apps.ps1 currently ($ScriptVersion)"
Exit
}
Foreach ($i in $packages) {
Continue
$tmpname = $packagesLanguage.$($i[1])
$tmppackage = $i[1]
$tmpversion = $i[2]
$tmpsuggest = $i[3]
LogWrite "================= $tmpname ================="
if ($tmpversion -match $gversionm) { LogWrite "Windows $gversionm can access the App $tmpname" }
else {
LogWrite "Windows $gversionm cannot access the App $tmpname"
Continue
}
$fW = Get-AppxPackage $tmppackage
if ($fW) {
LogWrite $Languages."delete_found"
$choices = [System.Management.Automation.Host.ChoiceDescription[]](
(New-Object System.Management.Automation.Host.ChoiceDescription $Languages."yes", $Languages."delete"),
(New-Object System.Management.Automation.Host.ChoiceDescription $Languages."no", $Languages."keep"))
$Answer = $host.ui.PromptForChoice($Languages."delete_app",$Languages."delete_app_q"+$tmpname,$choices,($tmpsuggest))
if ($Answer -match '0') {
$op = Get-AppxPackage $tmppackage | Remove-AppxPackage
if ($op) {
LogWrite $Languages."successfully_deleted"
} else {
LogWrite $Languages."error_delete"
}
}
elseif ($Answer -match '1') { LogWrite $Languages."delete_skip" }
}
else {
LogWrite $Languages."didnt_found"
$choices = [System.Management.Automation.Host.ChoiceDescription[]](
(New-Object System.Management.Automation.Host.ChoiceDescription $Languages."yes",$Languages."yes_install"),
(New-Object System.Management.Automation.Host.ChoiceDescription $Languages."no",$Languages."no_keep"))
$Answer = $host.ui.PromptForChoice($Languages."install",$Languages."install_q"+$tmpname,$choices,(1))
if ($Answer -match '0') {
$op = Get-AppxPackage -AllUsers $tmppackage | Foreach { Add-AppxPackage -DisableDevelopmentMode -Register "$
($_.InstallLocation)\AppXManifest.xml"}
if ($op) {
LogWrite $Languages."successfully_installed"
} else {
LogWrite $Languages."error_install"
}
}
elseif ($Answer -match '1') { LogWrite $Languages."install_skip" }
}
}
$choices = [System.Management.Automation.Host.ChoiceDescription[]](
(New-Object System.Management.Automation.Host.ChoiceDescription $Languages."yes_all", $Languages."yes_all_q"),
(New-Object System.Management.Automation.Host.ChoiceDescription $Languages."no_all", $Languages."no_all_q"))
$Answer = $host.ui.PromptForChoice($Languages."delete_all",$Languages."delete_all_q"+$s.Name,$choices,(1))
if ($Answer -match '0') {
$allApps = Get-AppxPackage | Select Name
Foreach ($s in $allApps) {
Foreach ($b in $packages) {
if ($s.Name -eq $b[1]) {
$skip = 1
break
}
else { $shouldbeeq = $s.Name }
}
if ($skip -eq 1) { Continue }
else {
$tmpname = $s.Name
LogWrite "================= $tmpname ================="
$fW = Get-AppxPackage $s.Name
if ($fW) {
LogWrite $Languages."delete_found"
$choices = [System.Management.Automation.Host.ChoiceDescription[]](
(New-Object System.Management.Automation.Host.ChoiceDescription $Languages."yes", $Languages."delete"),
(New-Object System.Management.Automation.Host.ChoiceDescription $Languages."no", $Languages."keep"))
$Answer = $host.ui.PromptForChoice($Languages."delete_app",$Languages."delete_app_q"+$s.Name,$choices,(1))
if ($Answer -match '0') {
$op = Get-AppxPackage $s.Name | Remove-AppxPackage
if ($op) {
LogWrite $Languages."successfully_deleted"
} else {
LogWrite $Languages."error_delete"
}
}
elseif ($Answer -match '1') { LogWrite $Languages."delete_skip" }
}
}
}
}