-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtuneup.ps1
157 lines (139 loc) · 5.55 KB
/
tuneup.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
#version yyyy.mm.MAJ.MIN.r
#version 2022.06.2.1.3
$version = "202206.2.1.3"
$u=$env:UserName
$c=$env:COMPUTERNAME
Write-Output "Hi $u. "
$b="C:\Program Files\zAdmin"
$h = "C:\Windows\System32\drivers\etc\hosts"
$mo=Get-Date -UFormat %b
$sched = "Jan", "Mar", "May", "Jul", "Sep", "Nov"
Write-Host "You are running version $version of Spam Defender."
$task = Read-Host "Do you need a reboot (r) OR shutdown(s) OR keep awake(k)"
$task = $task.ToUpper()
try {
if(Test-Path -Path $b) {
Write-Host "The folder already exists"
}
else{
mkdir $b
}
}
catch {
{1:<#Do this if a terminating exception happens#>}
}
function msdtTest {
try {
New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT -Name HKCR
}
catch {
-ErrorAction Ignore
}
Set-Location -Path HKCR:\
$keyname = "HKCR:\ms-msdt"
if ( Get-ChildItem -Path $keyname -ErrorAction Ignore ) {
Write-Host "it exists" -ForegroundColor Red
Remove-Item -Recurse -Force $keyname -WhatIf
Write-Host "MSDT is removed." -ForegroundColor Green
}
else {
write-host "MSDT is already gone." -ForegroundColor Green
}
}
function stateTogg {
if ( $task -eq 'S' ) {
Stop-Computer -Force
}
elseif ($task -eq 'R') {
Restart-Computer -Force
}
else { Write-Host "Keeping awake"}
}
function gitUpdater{
try {
Set-Location $HOME\Downloads
Write-Host "Updating the maintenance and security files" -ForegroundColor Yellow
Invoke-WebRequest -Uri https://raw.githubusercontent.com/mrcodelab/familytuneup/main/tuneup.ps1 -OutFile 'tuneup.ps1'
$zip1 = Get-FileHash -Algorithm SHA256 $HOME\Downloads\tuneup.ps1 | Select-Object -ExpandProperty Hash
Invoke-WebRequest -Uri https://raw.githubusercontent.com/mrcodelab/hashes/main/tuneup-hash.txt -OutFile 'tuneup-hash.txt'
$hash1 = Get-Content $HOME\Downloads\tuneup-hash.txt
if ( $zip1 -eq $hash1 ) {
Move-Item tuneup.ps1 $b -Force
Write-Host "Tuneup file updated." -ForegroundColor Green
}
else { Write-Host "The tuneup hash did not match!" -ForegroundColor Red }
}
catch {
Write-Host "" -ErrorAction SilentlyContinue
}
try {
Invoke-WebRequest -Uri https://raw.githubusercontent.com/mrcodelab/pihole-g/main/hosts -OutFile 'hosts'
$zip2 = Get-FileHash -Algorithm SHA256 $HOME\Downloads\hosts | Select-Object -ExpandProperty Hash
Invoke-WebRequest -Uri https://raw.githubusercontent.com/mrcodelab/hashes/main/hosts_hash.txt -OutFile 'hosts_hash.txt'
$hash2 = Get-Content $HOME\Downloads\hosts_hash.txt
Write-Host $zip2
write-host $hash2
if ( $zip2 -eq $hash2 ) {
$ucheck = Get-FileHash -Algorithm SHA256 $h | Select-Object -ExpandProperty Hash
if ( $hash2 -ne $ucheck ) {
Write-Host "The hosts file has been updated. Please disable your antivirus and re-run spamdefender to get the latest filter."
Move-Item $Home\Downloads\hosts $h -Force -ErrorAction SilentlyContinue
}
Move-Item $Home\Downloads\hosts $h -Force
Write-Host "Hosts file updated." -ForegroundColor Green
}
else { Write-Host "The host hash did not match! The host file was not updated." -ForegroundColor Red }
}
catch {
Write-Host "Security file update blocked by antivirus. No biggie." -ForegroundColor White -ErrorAction SilentlyContinue
}
}
function updater {
Get-WUInstall -Install -AcceptAll -AutoReboot -Hide
Get-WUInstall -MicrosoftUpdate -Install -AcceptAll -AutoReboot -Hide
}
function dldclnr {
if( $c -ne "MightyMouse"){
Remove-Item -Path $Home\Downloads\* -Recurse -Force
Write-Host "Done cleaning downloads" -ForegroundColor Green
}
else {
Remove-Item $HOME\Downloads\*.gz -Recurse
Write-Host "Not deleting downloads folder"
}
}
function cleanup {
Set-Location $HOME
Clear-RecycleBin -DriveLetter C -Force -ErrorAction SilentlyContinue
Write-Host "Recycle Bin cleaned - Ignore the error. It works." -ForegroundColor Green
dldclnr
Write-Host "Cleaning the temp folder." -ForegroundColor Yellow
Remove-Item -Path C:\Windows\Temp\* -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "Temp folder cleaned." -ForegroundColor Green
Set-Location $PSScriptRoot
Start-Process -FilePath "C:\WINDOWS\system32\cleanmgr.exe" /sagerun:1 | Out-Null
Wait-Process -Name cleanmgr
Start-Process -FilePath "C:\Program Files (x86)\Wise\Wise Registry Cleaner\WiseRegCleaner.exe"
}
function common {
Write-Host "Testing MSDT vulnerability" -ForegroundColor Yellow
msdtTest
Set-Location $b
Write-Host "Updating Windows" -ForegroundColor Yellow
updater
gitUpdater
Write-Host "Windows update complete." -ForegroundColor Green
Write-Host "Cleaning up the system bloat" -ForegroundColor Yellow
cleanup
Write-Host "Disk cleanup complete." - -ForegroundColor Green
stateTogg
Set-Location $HOME
}
Write-Host "Running common workload" -ForegroundColor Yellow
common
Write-Host "Thank you for using Spam Defender!"
if (( $u -eq "mateusz" ) -and ( $mo -in $sched )) {
Write-Host "running admin special" -ForegroundColor Yellow
& "$PSScriptRoot\pwmaintenance.ps1"
} else { Write-Host "Not now Madeline" -ForegroundColor Blue}
Stop-Process -Name powershell