I have a PS script that is menu driven. The functionality of the menu is perfect for what I want. The problem is I cant seem to figure out where to put the cmdlets for proper execution. I have all the cmdlets working when not in the menu script. Please help!!!
Here is my menu script.
Function Show-Menu {
Param(
[Parameter(Position=0,Mandatory=$True,HelpMessage="Enter your menu text")]
[ValidateNotNullOrEmpty()]
[string]$Menu,
[Parameter(Position=1)]
[ValidateNotNullOrEmpty()]
[string]$Title="Menu",
[switch]$ClearScreen)
if ($ClearScreen) {Clear-Host}
#build the menu prompt
$menuPrompt=$title
#add a return
$menuprompt+="`n"
#add an underline
$menuprompt+="-"*$title.Length
$menuprompt+="`n"
#add the menu
$menuPrompt+=$menu
Read-Host -Prompt $menuprompt
} #end function
#define a menu here
$menu=@"
1 Show Services
2 Show Processes
3 Show System Information
Q Quit
Select a task by number or Q to quit
"@
#Keep looping and running the menu until the user selects Q (or q).
Do {
#use a Switch construct to take action depending on what menu choice is selected.
Switch (Show-Menu $menu "System Utilities" -clear) {
"1" {Write-Host "Listing services" -ForegroundColor Yellow
sleep -seconds 2}
"2" {Write-Host "Listing Processes" -ForegroundColor Green
sleep -seconds 2}
"3" {Write-Host "Pulling System Information" -ForegroundColor Magenta
sleep -seconds 2}
"Q" {Write-Host "Goodbye" -ForegroundColor Cyan
Return
}
Default {Write-Warning "Invalid Choice. Try again."
sleep -seconds 2}
} #switch
} While ($True)
↧
Need help with a script
↧