-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpsreference.ps1
55 lines (46 loc) · 1.51 KB
/
psreference.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
# Load JSON from URL
$url = "https://raw.githubusercontent.com/superswan/Powershell-SysAdmin/refs/heads/master/commands.json"
$commands = Invoke-RestMethod -Uri $url
Write-Host "☆ PowerShell Reference ☆"
Write-Host "https://github.com/superswan/Powershell-SysAdmin/`n"
# Display Menu
function Show-Menu {
$i = 1
$menuItems = @()
foreach ($command in $commands) {
Write-Host "$i." -NoNewline
Write-Host "$($command.title)" -ForegroundColor Yellow -NoNewline
Write-Host ": $($command.description)"
$menuItems += [PSCustomObject]@{
Index = $i
Title = $command.title
Command = $command.command
}
$i++
}
return $menuItems
}
function Execute-Command {
param (
[int]$choice,
[array]$menuItems
)
$selectedCommand = $menuItems | Where-Object { $_.Index -eq $choice }
if ($selectedCommand) {
Invoke-Expression $selectedCommand.Command
Read-Host -Prompt "`nPress Enter to return to the menu."
} else {
Write-Host "Invalid selection."
}
}
# Main Loop
while ($true) {
$menuItems = Show-Menu
$choice = Read-Host -Prompt "Enter the number of the command to run or 'q' to quit"
if ($choice -eq 'q') { break }
if ($choice -match '^\d+$' -and ([int]$choice -le $menuItems.Count) -and ([int]$choice -gt 0)) {
Execute-Command -choice ([int]$choice) -menuItems $menuItems
} else {
Write-Host "Invalid choice. Please enter a valid number."
}
}