-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathManagementMenu.ps1
More file actions
101 lines (90 loc) · 3.45 KB
/
ManagementMenu.ps1
File metadata and controls
101 lines (90 loc) · 3.45 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
Clear-Host
# Title for your menu system
$title = " Helpdesk Menu "
# Advanced menu title
$advTitle = " Advanced Menu "
# Main menu header, centered between 50 dashes
$mmHeader = "-"*25 + $title + "-"*25
# Create the advanced menu header to match width of main menu header
# compensating for a length that has an odd number of characters
$numDashes = ($mmHeader.length - $advTitle.Length) / 2
If ($numDashes -is [double]) {
$leftDashes = [math]::Floor($numDashes)
$rightDashes = [math]::Floor($numDashes) +1
} Else {
$leftDashes = $numDashes
$rightDashes = $numDashes
}
$advHeader = "-"*$leftDashes + $advTitle + "-"*$rightDashes
# Build paths
$scripts = Split-Path -parent $PSCommandPath
# Path to subfolder which contains scripts to go under the "Main Menu"
[array]$mmFiles = get-childItem $scripts\MainMenu | where {($_.name -like "*.ps1") -and (-not($_.basename -like "*test*"))}
# Path to subfolder which contains scripts to go under the "Advanced Menu" - less used, or more resource intensive scripts
[array]$advFiles = get-childItem $scripts\AdvancedMenu | where {($_.name -like "*.ps1") -and (-not($_.basename -like "*test*"))}
# The main menu - most frequently used scripts
Function mainMenu {
Clear-Host
# Main Menu Header
Write-Host $mmHeader -foregroundcolor green -backgroundcolor darkgray
# Check if the MainMenu folder contains any scripts
If ($mmFiles) {
# Build the menu choices based on all .ps1 files found in $mmFiles
for ($i=0; $i -le $mmFiles.GetUpperBound(0); $i++){
Write-Host `t$($i+1)"."($mmFiles[$i].basename) -foregroundcolor white
}
# Add the advanced menu option as the last choice
Write-Host `t$(($mmFiles | measure).count +1)". Advanced Menu"`n -foregroundcolor cyan
# Prompt for a choice
Write-Host "Please enter a number... " -nonewline
$choice = Read-Host
while(1..(($mmFiles | measure).count +1) -Notcontains $choice){
$choice = Read-Host "Enter a number...Or else"
}
if (1..(($mmFiles | measure).count) -contains $choice){
# Run the chosen script
& ("$scripts\MainMenu\"+$mmFiles[[int]$choice-1].name)
}
elseif ($choice -eq ($mmFiles | measure).count +1){
advancedMenu
}
}
}
Function advancedMenu {
Clear-Host
# Advanced Menu Header
Write-Host $mmHeader -foregroundcolor green -backgroundcolor darkgray
Write-Host $advHeader -foregroundcolor gray -backgroundcolor red
# Check if the advanced folder contains any scripts
If ($advFiles) {
# Build the menu choices based on all .ps1 files found in $advFiles
for ($i=0; $i -le $advFiles.GetUpperBound(0); $i++){
Write-Host `t$($i+1)"."($advFiles[$i].basename) -foregroundcolor white
}
# Add the Main Menu option as the last choice
Write-Host `t$(($advFiles | measure).count +1)". Main Menu"`n -foregroundcolor cyan
# Prompt for a choice
Write-Host "Please enter a number... " -nonewline
$choice = Read-Host
while(1..(($advFiles | measure).count +1) -Notcontains $choice){
$choice = Read-Host "Enter a number...Or else"
}
if (1..(($advFiles | measure).count) -contains $choice){
# Run the chosen script
& ("$scripts\AdvancedMenu\"+$advFiles[[int]$choice-1].name)
}
elseif ($choice -eq ($advFiles | measure).count +1){
mainMenu
}
}
Else {
Write-Host `n`t"No scripts in the advanced folder"
# Prompt to return
Write-Host `n"Press Enter to return to the Main Menu or any other key to cancel" -foregroundcolor cyan
If (($Host.UI.RawUI.ReadKey()).VirtualKeyCode -eq 13){
mainMenu
}
}
}
# Call the main menu
mainMenu