-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.ps1
253 lines (230 loc) · 8.82 KB
/
script.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
function Invoke-CommandAsAdmin {
param (
[string]$Command
)
$script = "powershell -Command `"$Command`""
Start-Process -FilePath "powershell.exe" -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `$script" -Verb RunAs -Wait
}
function Show-AsciiHeader {
param(
[string]$Title = "MENU",
[ConsoleColor]$Color = "Green",
[int]$Width = 54
)
Write-Host ("╔" + ("═" * ($Width)) + "╗") -ForegroundColor $Color
$spacesNeeded = $Width - $Title.Length
if ($spacesNeeded -ge 0) {
$leftPad = [Math]::Floor($spacesNeeded / 2)
$rightPad = $spacesNeeded - $leftPad
$centeredTitle = (" " * $leftPad) + $Title + (" " * $rightPad)
} else {
$centeredTitle = $Title.Substring(0, $Width)
}
Write-Host ("║" + $centeredTitle + "║") -ForegroundColor $Color
Write-Host ("╚" + ("═" * ($Width)) + "╝") -ForegroundColor $Color
Write-Host ""
}
function Show-AsciiFooter {
param(
[string]$Message = "",
[ConsoleColor]$Color = "Green",
[int]$Width = 54
)
Write-Host ""
Write-Host ("╔" + ("═" * ($Width)) + "╗") -ForegroundColor $Color
if ($Message) {
$spacesNeeded = $Width - $Message.Length
if ($spacesNeeded -ge 0) {
$leftPad = [Math]::Floor($spacesNeeded / 2)
$rightPad = $spacesNeeded - $leftPad
$centeredMessage = (" " * $leftPad) + $Message + (" " * $rightPad)
} else {
$centeredMessage = $Message.Substring(0, $Width)
}
Write-Host ("║" + $centeredMessage + "║") -ForegroundColor $Color
}
Write-Host ("╚" + ("═" * ($Width)) + "╝") -ForegroundColor $Color
Write-Host ""
}
function Show-MenuPrompt {
param(
[string]$Message
)
return Read-Host $Message
}
########################################################
# Task Definitions #
########################################################
# Installation Menu tasks
$global:InstallTasks = @(
@{
Name = "Install Brave";
Action = { winget install -e --id Brave.Brave }
},
@{
Name = "Install Visual Studio Code";
Action = { winget install -e --id Microsoft.VisualStudioCode }
},
@{
Name = "Install GitHub Desktop";
Action = { winget install -e --id GitHub.GitHubDesktop }
},
@{
Name = "Install Node.js & NPM";
Action = { winget install -e --id OpenJS.NodeJS }
},
@{
Name = "Install Python";
Action = { winget install -e --id Python.Python.3 }
},
@{
Name = "Install Docker";
Action = { winget install -e --id Docker.DockerDesktop }
}
)
function Display-InstallMenu {
Clear-Host
Show-AsciiHeader -Title "INSTALLATION MENU" -Color Green -Width 54
for ($i = 0; $i -lt $global:InstallTasks.Count; $i++) {
$task = $global:InstallTasks[$i]
Write-Host "$($i + 1)) $($task.Name)" -ForegroundColor Yellow
}
Show-AsciiFooter -Message "Type the number to install a program | Type 'BACK' to return" -Color Green -Width 54
do {
$choice = Show-MenuPrompt -Message "Enter your choice (1-$($global:InstallTasks.Count) or BACK)"
if ($choice -match "^\d+$" -and [int]$choice -ge 1 -and [int]$choice -le $global:InstallTasks.Count) {
$taskIndex = [int]$choice - 1
Write-Host "Installing: $($global:InstallTasks[$taskIndex].Name)" -ForegroundColor Green
& $global:InstallTasks[$taskIndex].Action
} elseif ($choice.ToUpper() -eq "BACK") {
return
} else {
Write-Host "Invalid choice. Please try again." -ForegroundColor Red
}
} while ($true)
}
# Other tasks
$global:Tasks = @(
@{
Name = "Installation Menu";
Selected= $false;
Action = { Display-InstallMenu }
},
@{
Name = "Organize files by type";
Selected= $false;
Action = {
$path = Show-MenuPrompt -Message "Enter the directory path"
Get-ChildItem -Path $path -File | Group-Object Extension | ForEach-Object {
$ext = $_.Name
$folder = Join-Path -Path $path -ChildPath $ext
if (-not (Test-Path -Path $folder)) {
New-Item -ItemType Directory -Path $folder | Out-Null
}
$_.Group | Move-Item -Destination $folder
}
}
},
@{
Name = "Clear Temp Files";
Selected= $false;
Action = {
Write-Host "Clearing Temp Files..." -ForegroundColor Green
Remove-Item -Path $env:TEMP\* -Recurse -Force -ErrorAction SilentlyContinue
}
},
@{
Name = "Activate Windows";
Selected= $false;
Action = {
$cmdUrl = 'https://raw.githubusercontent.com/massgravel/Microsoft-Activation-Scripts/refs/heads/master/MAS/Separate-Files-Version/Activators/Online_KMS_Activation.cmd'
$tempFile = "$env:TEMP\Online_KMS_Activation.cmd"
Invoke-RestMethod -Uri $cmdUrl -OutFile $tempFile
Invoke-CommandAsAdmin -Command "cmd.exe /c $tempFile /K-Windows"
Remove-Item -Path $tempFile -Force
}
},
@{
Name = "Activate Microsoft Office";
Selected= $false;
Action = {
$cmdUrl = 'https://raw.githubusercontent.com/massgravel/Microsoft-Activation-Scripts/refs/heads/master/MAS/Separate-Files-Version/Activators/Online_KMS_Activation.cmd'
$tempFile = "$env:TEMP\Online_KMS_Activation.cmd"
Invoke-RestMethod -Uri $cmdUrl -OutFile $tempFile
Invoke-CommandAsAdmin -Command "cmd.exe /c $tempFile /K-Office"
Remove-Item -Path $tempFile -Force
}
},
@{
Name = "Clean Windows Update Cache";
Selected= $false;
Action = {
Write-Host "Stopping Windows Update Service..." -ForegroundColor Green
Invoke-CommandAsAdmin -Command "Stop-Service wuauserv -Force"
Write-Host "Deleting Windows Update cache files..." -ForegroundColor Green
Invoke-CommandAsAdmin -Command "Remove-Item -Path 'C:\Windows\SoftwareDistribution\*' -Recurse -Force -ErrorAction SilentlyContinue"
Write-Host "Starting Windows Update Service..." -ForegroundColor Green
Invoke-CommandAsAdmin -Command "Start-Service wuauserv"
}
}
)
########################################################
# Core Menu Functions #
########################################################
# Function to reset all tasks to off
function Reset-Tasks {
foreach ($task in $global:Tasks) {
$task.Selected = $false
}
}
# Function to display the menu
function Display-Menu {
Clear-Host
Show-AsciiHeader -Title "MAIN MENU" -Color Green -Width 54
for ($i = 0; $i -lt $global:Tasks.Count; $i++) {
$task = $global:Tasks[$i]
$status = if ($task.Selected) { "[✔]" } else { "[ ]" }
Write-Host "$($i + 1)) $status $($task.Name)" -ForegroundColor Yellow
}
Show-AsciiFooter -Message "Type the number to toggle a task | START to execute | EXIT to quit" -Color Green -Width 54
}
# Function to execute all selected tasks
function Execute-Tasks {
Write-Host "Executing selected tasks..." -ForegroundColor Yellow
foreach ($task in $global:Tasks) {
if ($task.Selected) {
Write-Host "Executing: $($task.Name)" -ForegroundColor Cyan
Start-Sleep -Seconds 2
& $task.Action
Write-Host "Task complete: $($task.Name)" -ForegroundColor Cyan
$task.Selected = $false
Display-Menu
}
}
Write-Host "All selected tasks completed!" -ForegroundColor Green
Start-Sleep -Seconds 2
}
########################################################
# Main Loop #
########################################################
do {
Display-Menu
$choice = Show-MenuPrompt -Message "Enter your choice (1-$($global:Tasks.Count), START, or EXIT)"
if ($choice -match "^\d+$" -and [int]$choice -ge 1 -and [int]$choice -le $global:Tasks.Count) {
$taskIndex = [int]$choice - 1
$global:Tasks[$taskIndex].Selected = -not $global:Tasks[$taskIndex].Selected
Write-Host "Toggled $($global:Tasks[$taskIndex].Name) to: $($global:Tasks[$taskIndex].Selected)" -ForegroundColor Yellow
Start-Sleep -Milliseconds 500
}
elseif ($choice.ToUpper() -eq "START") {
Execute-Tasks
}
elseif ($choice.ToUpper() -eq "EXIT") {
Write-Host "Exiting..." -ForegroundColor Red
break
}
else {
Write-Host "Invalid choice. Please try again." -ForegroundColor Red
Start-Sleep -Milliseconds 500
}
} while ($true)