Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
414 views
in Technique[技术] by (71.8m points)

powershell - Menus and submenus

Main menu:

1 Delete
2 Create
3 Modify
4 Remove
X Exit

Submenu 1 (for Delete):

1 Delete file
2 Delete folder
3 Delete another file
4 Delete another folder
5 Back to Main Menu

Submenu 2 (for Create):

1 Create Virtual
2 Create another Virtual
3 Back to Main Menu

Submenu 3 (for Modify):

1 Modify Virtual
2 Modify another Virtual
3 Back to Main Menu

This is the main menu:

$q = Read-Host "
Please select an option:
1 Delete Files 
2 Create New Virtual
3 Modify Existing Virtual
"

Sub-Menu1

$su1 = Read-Host "
Please select an option
1 Delete a file
2 Delete a folder
3 Delete another file
4 Delete another folder
5 Back to main menu
"

How do I take option 5 and bring it back to the main menu?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could create functions for each menu going through a switch so that you could keep calling new menus

function mainMenu(){
    clear
    switch(Read-Host "1 Delete
2 Create
3 Modify
4 Remove
X Exit"){
        X {break}
        2 {createMenu}
        default {"N/A"}
    }
}

function createMenu(){
    clear
    switch(Read-Host "Please select an option `
1 Delete a file
2 Delete a folder
3 Delete another file
4 Delete another folder
5 Back to main menu"){
        5 {mainMenu}
        default {"N/A"}
    }
}

mainMenu

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...