-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeployment.ps1
306 lines (272 loc) · 12.6 KB
/
Deployment.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
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
if ($PSVersionTable.PSVersion.Major -lt 3) {
[String] $PSScriptRoot = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
}
if ($PSVersionTable.PSVersion.Major -lt 3) {
[String] $PSCommandPath = $MyInvocation.MyCommand.Definition
}
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Start-Process -FilePath "powershell" -WorkingDirectory $PSScriptRoot -Verb runAs `
-ArgumentList "-NoProfile -ExecutionPolicy Bypass -File $PSCommandPath $env:USERNAME"
return
}
Import-LocalizedData -BaseDirectory $PSScriptRoot\Locales -BindingVariable Messages
Import-Module -Name (Join-Path -Path $PSScriptRoot\Modules -ChildPath Get-Choice)
# You can remove or apply your custom choices to this arrays.
# Applications
[Array] $Applications = @(
"Microsoft.MicrosoftSolitaireCollection",
"Microsoft.3DBuilder",
"Microsoft.BingSports",
"Microsoft.WindowsMaps",
"Microsoft.MicrosoftOfficeHub",
"Microsoft.WindowsPhone",
"Microsoft.WindowsDVDPlayer",
"Microsoft.BingWeather",
"Microsoft.ZuneVideo",
"Microsoft.ZuneMusic",
"Microsoft.Office.OneNote",
"Microsoft.Windows.Photos",
"Microsoft.XboxApp",
"Microsoft.XboxIdentityProvider",
"Microsoft.WindowsAlarms",
"Microsoft.WindowsSoundRecorder",
"Microsoft.People",
"Microsoft.WindowsCalculator",
"Microsoft.WindowsCamera",
"microsoft.windowscommunicationsapps",
"Microsoft.CommsPhone",
"Microsoft.Office.Sway",
"Microsoft.SkypeApp",
"Microsoft.BingFinance",
"Microsoft.Getstarted",
"Microsoft.BingNews",
"Microsoft.Messaging",
"Microsoft.OneConnect",
"Microsoft.ConnectivityStore",
"Microsoft.MicrosoftStickyNotes",
"Microsoft.Advertising.Xaml",
"9E2F88E3.Twitter",
"king.com.CandyCrushSodaSaga"
)
# Windows Optional Features
[Array] $Features = @(
"Internet-Explorer-Optional-amd64",
"MediaPlayback",
"WindowsMediaPlayer",
"WorkFolders-Client"
)
# Windows Firewall Rule Groups
[Array] $Groups = @(
"Xbox",
"OneNote",
"DiagTrack",
"Store Purchase App",
"windows_ie_ac_001",
"Microsoft.AAD.BrokerPlugin",
"Microsoft.Windows.CloudExperienceHost",
"Microsoft.WindowsStore",
"Microsoft.Appconnector",
"Microsoft.AccountsControl",
"Microsoft.ZuneVideo",
"Microsoft.ZuneMusic",
"Microsoft.Windows.ParentalControls",
"Microsoft.Windows.Cortana",
"Microsoft.WindowsFeedback",
"Microsoft.Windows.ContentDeliveryManager",
"Microsoft.Windows.Photos",
"Microsoft.WindowsDVDPlayer",
"Microsoft.WindowsStore",
"Microsoft.WindowsMaps",
"Microsoft.People",
"Microsoft.MicrosoftEdge",
"microsoft.windowscommunicationsapps",
"Microsoft.Getstarted",
"Microsoft.BingWeather",
"Microsoft.BingNews",
"Microsoft.BingFinance",
"Microsoft.XboxIdentityProvider",
"Microsoft.XboxGameCallableUI",
"Microsoft.LockApp",
"Microsoft.ConnectivityStore",
"Windows.ContactSupport",
"Windows.PurchaseDialog"
"Microsoft.Microsoft3DViewer",
"Microsoft.MSPaint",
"EnvironmentsApp",
"Holographic Item Player",
"Microsoft.PPIProjection",
"Microsoft.Windows.HolographicFirstRun",
"Microsoft.Windows.OOBENetworkCaptivePortal",
"Wallet",
"Microsoft.Windows.SecureAssessmentBrowser",
"Microsoft.StorePurchaseApp",
"Print 3D",
"Microsoft Pay",
"Microsoft.Windows.Apprep",
"Microsoft.Windows.SecHealthUI"
)
# Windows Services
$Services = @(
"diagnosticshub.standardcollector.service" # Microsoft (R) Diagnostics Hub Standard Collector Service
"DiagTrack" # Diagnostics Tracking Service
"dmwappushservice" # WAP Push Message Routing Service
#"HomeGroupListener" # HomeGroup Listener
#"HomeGroupProvider" # HomeGroup Provider
"lfsvc" # Geolocation Service
"MapsBroker" # Downloaded Maps Manager
#"NetTcpPortSharing" # Net.Tcp Port Sharing Service
#"RemoteAccess" # Routing and Remote Access
#"RemoteRegistry" # Remote Registry
"SharedAccess" # Internet Connection Sharing (ICS)
"TrkWks" # Distributed Link Tracking Client
"WbioSrvc" # Windows Biometric Service
"WlanSvc" # WLAN AutoConfig
#"WMPNetworkSvc" # Windows Media Player Network Sharing Service
#"wscsvc" # Windows Security Center Service
#"WSearch" # Windows Search
"XblAuthManager" # Xbox Live Auth Manager
"XblGameSave" # Xbox Live Game Save Service
"XboxNetApiSvc" # Xbox Live Networking Service
)
# Script starts here
# Cortana
Import-Module -Name (Join-Path -Path $PSScriptRoot\Modules -ChildPath Set-Cortana)
if ((Set-Cortana -Action Status) -eq "True") {
$DisplayName = "Cortana"
$Choices = @(
(New-Object -TypeName System.Management.Automation.Host.ChoiceDescription -ArgumentList ("&{0}" -f $Messages."Yes"), $Messages."Disable"),
(New-Object -TypeName System.Management.Automation.Host.ChoiceDescription -ArgumentList ("&{0}" -f $Messages."No"), $Messages."Do nothing")
)
$Choice = Get-Choice -Choices $Choices -Default 1 -Caption $DisplayName -Message ($Messages."Disable: {0}?" -f $DisplayName)
switch ($Choice) {
0 {
Set-Cortana -Action Disable
}
}
} else {
$DisplayName = "Cortana"
$Messages."You already disabled {0}." -f $DisplayName
}
# OneDrive
Import-Module -Name (Join-Path -Path $PSScriptRoot\Modules -ChildPath Set-OneDrive)
if ((Set-OneDrive -Action Status) -eq "True") {
$DisplayName = "OneDrive"
$Choices = @(
(New-Object -TypeName System.Management.Automation.Host.ChoiceDescription -ArgumentList ("&{0}" -f $Messages."Yes"), $Messages."Disable"),
(New-Object -TypeName System.Management.Automation.Host.ChoiceDescription -ArgumentList ("&{0}" -f $Messages."No"), $Messages."Do nothing")
)
$Choice = Get-Choice -Choices $Choices -Default 1 -Caption $DisplayName -Message ($Messages."Disable: {0}?" -f $DisplayName)
switch ($Choice) {
0 {
Set-OneDrive -Action Uninstall
}
}
} else {
$DisplayName = "OneDrive"
$Messages."You already disabled {0}." -f $DisplayName
}
# Windows Default Applications
foreach ($Application in $Applications) {
$Package = Get-AppxPackage -AllUsers -Name $Application
if ($Package) {
$InstallState = (Get-AppxPackage -AllUsers -Name $Application | Select-Object -ExpandProperty PackageUserInformation | Select-Object -Property InstallState)
if ($InstallState -match "Installed") {
$Choices = @(
(New-Object -TypeName System.Management.Automation.Host.ChoiceDescription -ArgumentList ("&{0}" -f $Messages."Yes"), $Messages."Remove Application"),
(New-Object -TypeName System.Management.Automation.Host.ChoiceDescription -ArgumentList ("&{0}" -f $Messages."No"), $Messages."Do nothing")
)
$Choice = Get-Choice -Choices $Choices -Default 1 -Caption $Application -Message ($Messages."Remove Application: {0}?" -f $Application)
switch ($Choice) {
0 {
$Package | Remove-AppxPackage
}
}
} else {
$Messages."You already removed the following Application: {0}" -f $Application
}
}
}
# Windows Optional Features
foreach ($Feature in $Features) {
if (Get-WindowsOptionalFeature -FeatureName $Feature -Online -ErrorAction SilentlyContinue | Where-Object {$_.State -eq "Enabled"}) {
$Choices = @(
(New-Object -TypeName System.Management.Automation.Host.ChoiceDescription -ArgumentList ("&{0}" -f $Messages."Yes"), $Messages."Disable Windows Optional Feature"),
(New-Object -TypeName System.Management.Automation.Host.ChoiceDescription -ArgumentList ("&{0}" -f $Messages."No"), $Messages."Do nothing")
)
$Choice = Get-Choice -Choices $Choices -Default 1 -Caption $Feature -Message ($Messages."Disable Windows Optional Feature: {0}?" -f $Feature)
switch ($Choice) {
0 {
Disable-WindowsOptionalFeature -Online -NoRestart -FeatureName $Feature
}
}
} else {
$Messages."You already disabled the following Windows Optional Feature: {0}" -f $Feature
}
}
# Firewall Groups
foreach ($Group in $Groups) {
foreach ($Rule in Get-NetFirewallRule -Group *${Group}*) {
if (Get-NetFirewallRule -Name $Rule.Name | Where-Object {$_.Enabled -eq "True"}) {
$Choices = @(
(New-Object -TypeName System.Management.Automation.Host.ChoiceDescription -ArgumentList ("&{0}" -f $Messages."Yes"), $Messages."Disable Firewall Rule"),
(New-Object -TypeName System.Management.Automation.Host.ChoiceDescription -ArgumentList ("&{0}" -f $Messages."No"), $Messages."Do nothing")
)
$Choice = Get-Choice -Choices $Choices -Default 1 -Caption $Rule.DisplayName -Message ($Messages."Disable Firewall Rule: {0}?" -f $Rule.DisplayName)
switch ($Choice) {
0 {
Set-NetFirewallRule -Name $Rule.Name -Enabled False
}
}
} elseif (Get-NetFirewallRule -Name $Rule.Name | Where-Object {$_.Enabled -eq "False"}) {
$Messages."You already disabled the following Firewall Rule: {0}" -f $Rule.DisplayName
}
}
}
# Services
foreach ($Service in $Services) {
if (-not (Get-Service -Name $Service | Where-Object {$_.StartType -eq "Disabled"})) {
$DisplayName = $(Get-Service -Name $Service | Select-Object -ExpandProperty DisplayName)
$Choices = @(
(New-Object -TypeName System.Management.Automation.Host.ChoiceDescription -ArgumentList ("&{0}" -f $Messages."Yes"), $Messages."Disable Service"),
(New-Object -TypeName System.Management.Automation.Host.ChoiceDescription -ArgumentList ("&{0}" -f $Messages."No"), $Messages."Do nothing")
)
$Choice = Get-Choice -Choices $Choices -Default 1 -Caption $DisplayName -Message ($Messages."Disable Service: {0}?" -f $DisplayName)
switch ($Choice) {
0 {
Get-Service -Name $Service | Set-Service -StartupType Disabled
Get-Service -Name $Service | Set-Service -Status Stopped -ErrorAction SilentlyContinue
}
}
} elseif (Get-Service -Name $Service | Where-Object {$_.StartType -eq "Disabled"}) {
$DisplayName = $(Get-Service -Name $Service | Select-Object -ExpandProperty DisplayName)
$Messages."You already disabled the following Service: {0}" -f $DisplayName
}
}
# HomeProvider
# Telemetry
# TimeServer
# XBox Game Overlay UI and Game DVR
$AppCaptureEnabled = Get-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\GameDVR -Name AppCaptureEnabled -ErrorAction SilentlyContinue
$GameDVR_Enabled = Get-ItemProperty -Path HKCU:\System\GameConfigStore -Name GameDVR_Enabled -ErrorAction SilentlyContinue
if ($AppCaptureEnabled -eq 1 -or $GameDVR_Enabled -eq 1) {
$Choices = @(
(New-Object -TypeName System.Management.Automation.Host.ChoiceDescription -ArgumentList ("&{0}" -f $Messages."Yes"), $Messages."Disable XBox Game DVR"),
(New-Object -TypeName System.Management.Automation.Host.ChoiceDescription -ArgumentList ("&{0}" -f $Messages."No"), $Messages."Do nothing")
)
$Choice = Get-Choice -Choices $Choices -Default 1 -Caption $Messages."XBox Game DVR" -Message $Messages."Disable XBox Game DVR?"
switch ($Choice) {
0 {
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\GameDVR -Name AppCaptureEnabled -Value 0
Set-ItemProperty -Path HKCU:\System\GameConfigStore -Name GameDVR_Enabled -Value 0
}
}
} else {
if (-not $AppCaptureEnabled) {
New-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\GameDVR -Name AppCaptureEnabled -Value 0 -PropertyType DWORD
}
if (-not $GameDVR_Enabled) {
New-ItemProperty -Path HKCU:\System\GameConfigStore -Name GameDVR_Enabled -Value 0
}
$Messages."You already disabled XBox Game DVR"
}
Read-Host -Prompt $Messages."You are done, press enter to exit"