-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommandlist.ps1
More file actions
43 lines (37 loc) · 1.27 KB
/
Copy pathcommandlist.ps1
File metadata and controls
43 lines (37 loc) · 1.27 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
# Define commands with descriptions, separated by '|'
$commandData = @"
ls -l | List directory contents
whoami | Display current user
df -h | Check disk space usage
uname -a | Display system information
"@
# Function to show command menu and get a valid selection
function Get-UserCommand {
$cmdArray = @()
# Split and process each line
$commandData -split "`n" | ForEach-Object {
# Split the command and its description
$parts = $_.Trim() -split '\|', 2
if ($parts.Count -eq 2) {
$command = $parts[0].Trim()
$description = $parts[1].Trim()
# Add command to the array and display the menu item
$index = $cmdArray.Count
Write-Host "$index $description"
$cmdArray += $command
}
}
# Input loop for valid command selection
do {
$choice = Read-Host "Enter the command number"
$isValid = $choice -match '^\d+$' -and $choice -ge 0 -and $choice -lt $cmdArray.Count
if (-not $isValid) {
Write-Host "Invalid choice, please try again."
}
} while (-not $isValid)
return $cmdArray[$choice]
}
# Main script execution
$selectedCommand = Get-UserCommand
Write-Host "Executing: $selectedCommand"
# Add logic to execute the command