Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8305311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:05:20+00:00 2026-06-08T18:05:20+00:00

I am wondering if it is possible to create switch cases with more than

  • 0

I am wondering if it is possible to create switch cases with more than 1 value per case. I am trying to take in user input in different ways.
The menu looks something like:

    $database = Read-Host "[1] db 1 [2] db2 [3] db3 [4] ALL dbs"

This is then passed as a parameter into 4 different functions, based off of what the user response is in my next Read-host.
Without making a ridiculous amount of cases, I want to be able to accept all possible inputs. Ie, if the user wants to see 2 databases, they can enter 32 or 23. If they want to see all, it would accept 4, 321, 123, 213… Currently I am trying to accomplish this by:

switch ($database) { 
(4 -or 123 -or 312 -or ...) {#return all paths}
(12 -or 21) { #return 1st 2 db paths}
(31 -or 13) { #return 1st and last db paths}
(1) {#return 1st db path}
...
}

This is causing a syntax error, so it clearly does not work.
As you can tell, there are going to be a lot of cases already (7). If I had to list out every single option there would be more than double (16). Is there a way to create a one to many association in a switch case? If not, does anyone have an idea of a new approach I can take to this problem?

SOLUTION

    switch -regex ($database)
            {
                "[*1*]" {"\\db1"}
                "[*2*]" {"\\db2"}
                "[*3*]" {"\\db3"} 
                "[4]" {"\\db1";"\\db2";"\\db3"}
                default {Write-Host "Database(s) were not properly specified,
 Please run the script again"
exit}
            }

This accomplishes what I was going for, although I was never able to figure out how to put a conditional -or in a switch statement, I do not believe it is possible

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:05:21+00:00Added an answer on June 8, 2026 at 6:05 pm

    I think that you can work on

    switch -regex ($database)
    

    -have a look here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering whether it is possible to create a new database and user,
I am wondering is it possible to create user groups on the fly when
I was wondering if it was possible to create a double rounded border without
I was wondering if it is possible to create a flash movie that rotates
I was wondering if it was possible to create a SPARQL UpdateRequest in Jena
I am wondering if it is possible to create a new dataframe with certain
Hey I was just wondering if it is possible to create an executable file
Just wondering if it is possible to dynamically create a list of strings in
I was wondering if it were possible to dynamically create an XML layout file
I was wondering if the following is possible. Create a class that accepts an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.