-
Notifications
You must be signed in to change notification settings - Fork 0
/
windows_cleanup.ps1
123 lines (104 loc) · 3.5 KB
/
windows_cleanup.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
<#
Service names to do stuff with later, maybe?
WSearch - Windows Search
sshd - ssh server
Spooler - Druckerwarteschlange
SEMgrSvc - Zahlungs- und NFC/SE-Manager
WinDefend - Windows Defender
WdNisSvc - Windows Defender Netzwerkinspektionsdienst
DiagTrack - Benutzererfahrung und Telemetrie im verbundenen Modus
#>
<#
Removes Windows Search Indexing.
Disable-WindowsOptionalFeature -Online -NoRestart -Remove -FeatureName SearchEngine-Client-Package
Remove-WindowsCapability -Online -Name Hello.Face.18330
#>
#SET VARIABLES
$WindowsOptionalFeatures2Remove=@(
"Internet-Explorer-Optional-x86",
"SMB1Protocol",
"SMB1Protocol-Client",
"SMB1Protocol-Deprecation",
"FaxServicesClientPackage",
"Printing-XPSServices-Features"
)
$AppXNames2Exclude=@(
"Dolby",
"Intel",
"Lenovo",
"Wacom",
"Realtek",
#The next line is important to allow for reinstallation of apps via powershell again. Also store is removable but would need to be reinstalled via
"store","extension","advertising","NET","UI","VCLibs"
)
#DEFINE FUNCTIONS
function Remove-OneDrive {
param ()
if($Env:PROCESSOR_ARCHITECTURE -match "x86") {
$SystemDir="System32"
}
else {
$SystemDir="SysWOW64"
}
$OneDriveExePath="$Env:SystemRoot\$($SystemDir)\OneDriveSetup.exe"
if (Test-Path $OneDriveExePath){
$OneDriveUninstExpr="$($OneDriveExePath) /uninstall"
#Make sure onedrive isn't ruinning anymore.
$OneDriveProcess=@(Get-Process "*onedrive*")
if ($OneDriveProcess.Count -ne 0 ) { Stop-Process -Force -Name OneDrive }
#Invoke Uninstall Expression
Invoke-Expression "$OneDriveUninstExpr"
}
}
function Install-OpenSSHServer {
param()
$sshd_installed={
Get-WindowsCapability -Online|
Where-Object Name -match "openssh.server"|
Select-Object State
}
if ($sshd_installed -notmatch "Installed") {
Add-WindowsCapability -Online -Name OpenSSH.Server
}
if ((Get-Service sshd).State -notmatch "Running") {
Set-Service sshd -StartupType AutomaticDelayedStart
Start-Service sshd
}
}
function Remove-WindowsOptionalFeatures {
param([Array] $WindowsOptionalFeatures2Remove)
Get-WindowsOptionalFeature -Online |
Where-Object State -EQ "Enabled"|
ForEach-Object {
if ($_.FeatureName -in $WindowsOptionalFeatures2Remove) {
Disable-WindowsOptionalFeature -Online -NoRestart -Remove -FeatureName $_.FeatureName
}
}
}
function Remove-AppXPackages {
param([array] $AppXNames2Exclude )
#Create List of all Packages that are removable at all.
$RemovablePackages=Get-AppxPackage -AllUsers | Where-Object { -not $_.NonRemovable }
#Filters that list according to pre-defined criteria
function FiltertMatchesInList {
param ($value, [Array]$List)
foreach ($item in $List) {
if ($value -match $item) {
return $False
}
}
return $True
}
#$Packa ges2Remove=$RemovablePackages | filterAgainstList $AppXNames2Exclude $_
$Packages2Remove=$RemovablePackages | Where-Object {
FiltertMatchesInList $_.Name $AppXNames2Exclude
}
$Packages2Remove | Remove-AppxPackage -AllUsers -ErrorAction Inquire
}
#DO STUFF
#Disable Windows Seach Webresults
Set-WindowsSearchSetting -EnableWebResultsSetting 0
Install-OpenSSHServer
Remove-WindowsOptionalFeatures($WindowsOptionalFeatures2Remove)
Remove-OneDrive
Remove-AppXPackages $AppXNames2Exclude