-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.ps1
More file actions
157 lines (134 loc) · 4.32 KB
/
Menu.ps1
File metadata and controls
157 lines (134 loc) · 4.32 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
$ScriptsPath = "X:\Scripts"
while ($true) {
Clear-Host
Write-Host "====================================="
Write-Host " WinPE Script Launcher"
Write-Host "====================================="
Write-Host ""
# Get script files
$scripts = Get-ChildItem -Path $ScriptsPath -Filter *.ps1 -File -ErrorAction SilentlyContinue |
Where-Object { $_.Name -ne "WinPE-Menu.ps1" } |
Sort-Object Name
# Get text files
$textFiles = Get-ChildItem -Path $ScriptsPath -Filter *.txt -File -ErrorAction SilentlyContinue |
Sort-Object Name
$hasScripts = $scripts -and $scripts.Count -gt 0
$hasTextFiles = $textFiles -and $textFiles.Count -gt 0
if (-not $hasScripts -and -not $hasTextFiles) {
Write-Host "No scripts or text files found in $ScriptsPath"
Write-Host ""
Write-Host "P. Open PowerShell"
Write-Host "R. Refresh"
Write-Host "X. Exit"
Write-Host ""
$choice = Read-Host "Select option"
switch ($choice.ToUpper()) {
"P" { powershell.exe -NoExit }
"R" { }
"X" { break }
default {
Write-Host "Invalid selection..."
Start-Sleep 1
}
}
continue
}
# Display scripts first
if ($hasScripts) {
Write-Host "Scripts:"
for ($i = 0; $i -lt $scripts.Count; $i++) {
Write-Host "$($i + 1). $($scripts[$i].Name)"
}
Write-Host ""
}
# Display text files at bottom
if ($hasTextFiles) {
Write-Host "Text Files:"
for ($i = 0; $i -lt $textFiles.Count; $i++) {
Write-Host "N$($i + 1). $($textFiles[$i].Name)"
}
Write-Host ""
}
Write-Host "P. Open PowerShell"
Write-Host "R. Refresh"
Write-Host "X. Exit"
Write-Host ""
$choice = Read-Host "Select option"
# ------------------------------
# Run script by number
# ------------------------------
if ($choice -match '^\d+$') {
$index = [int]$choice - 1
if ($hasScripts -and $index -ge 0 -and $index -lt $scripts.Count) {
$selectedScript = $scripts[$index].FullName
Clear-Host
Write-Host "====================================="
Write-Host "Running: $($scripts[$index].Name)"
Write-Host "====================================="
Write-Host ""
try {
& powershell.exe -ExecutionPolicy Bypass -File $selectedScript
}
catch {
Write-Host "Error running script:"
Write-Host $_
}
Write-Host ""
Write-Host "Press Enter to return to menu..."
Read-Host | Out-Null
}
else {
Write-Host "Invalid script number..."
Start-Sleep 1
}
continue
}
# ------------------------------
# Open text file in Notepad
# Example: N1, N2, N3
# ------------------------------
if ($choice -match '^[Nn](\d+)$') {
$textIndex = [int]$Matches[1] - 1
if ($hasTextFiles -and $textIndex -ge 0 -and $textIndex -lt $textFiles.Count) {
$selectedTextFile = $textFiles[$textIndex].FullName
Clear-Host
Write-Host "====================================="
Write-Host "Opening in Notepad: $($textFiles[$textIndex].Name)"
Write-Host "====================================="
Write-Host ""
try {
Start-Process notepad.exe $selectedTextFile -Wait
}
catch {
Write-Host "Error opening text file:"
Write-Host $_
Write-Host ""
Write-Host "Press Enter to return to menu..."
Read-Host | Out-Null
}
}
else {
Write-Host "Invalid text file selection..."
Start-Sleep 1
}
continue
}
# ------------------------------
# Other options
# ------------------------------
switch ($choice.ToUpper()) {
"P" {
powershell.exe -NoExit
}
"R" {
# refresh loop
}
"X" {
break
}
default {
Write-Host "Invalid selection..."
Start-Sleep 1
}
}
}