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 1030013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:38:05+00:00 2026-05-16T12:38:05+00:00

I have a nested switch statement inside a switch statement. I am wondering if

  • 0

I have a nested switch statement inside a switch statement. I am wondering if it is possible to grab the un-nested current item within the scope of the nested switch statement. I know I can accomplish this with a for loop with moderate difficulty but I am hoping there is some elegance I am missing to accomplishing this with switch statements. Below I am try to build some argument processing for one of my scripts.

# Process Args
$currentArg
$recurseOn = $false

:ListArgs switch -regex ($args)
{
    "-ou?" { $currentArg = "Organizational Unit"; write-host "Noticed ou switch"}
    "-li?k?e?" { $currentArg = "Compare To"; write-host "Noticed like switch"}
    "^-re?c?u?r?s?e?$" { $recurseOn = $true; write-host "Recurse switched on..."}
    default {
        :CurrentSwitch switch ($currentArg)
        {
            "Organizational Unit" { $OU = $_.$_ ; write-host "OU changed to '$($OU)'..."}
            "Compare To" { $Match = $_.$_ ; write-host "Lookup changed to '$($Match)'..."}
        }
    }
}

I know the present model of $.$ does not work but I am looking for something that could refer to the current item. I am thinking I could have a filler variable that I just fill with the current item regardless of condition and use that within the scope, but maybe there is something more elegant. I have also tried labeling my switch statements and attempted ‘ListArgs.$_’ to no avail.

Any input would be much appreciated. Thanks in advance!

I did this after posting:

    # Process Args
$currentArg
$recurseOn = $false

:ListArgs switch -regex ($args)
{
    "-ou?" { $currentArg = "Organizational Unit"; write-host "Noticed ou switch"}
    "-li?k?e?" { $currentArg = "Compare To"; write-host "Noticed like switch"}
    "^-re?c?u?r?s?e?$" { $recurseOn = $true; write-host "Recurse switched on..."}
    default {
        $item = $_
        :CurrentSwitch switch ($currentArg)
        {
            "Organizational Unit" { $OU = $item; write-host "OU changed to '$($OU)'..."}
            "Compare To" { $Match = $item; write-host "Lookup changed to '$($Match)'..."}
        }
    }
}

And was able to get it working, but any input on $_ or loop labels would be appreciated. Or is there a better way to do arg processing in PowerShell?

  • 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-05-16T12:38:06+00:00Added an answer on May 16, 2026 at 12:38 pm

    I guess since there are no better suggestions out there for argument processing, I answered my own question.

        $item = $_
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to have nested set capabilities in this somewhat custom setup? Consider
I have an application that has a toolbar with a UISegmentedControl nested inside of
I have this huge switch case with nested switch case statements in it that
I have a small web app I wrote that has a Dijit.layout.BorderContainer nested within
I have two divs nested in a containing div and want to continuously switch
I have nested list of the following form: my_list = [['Some1', '2', '3.6', '4.5',
I have nested iframes and I would like to use onload function for the
What if I have nested loops, and I want to break out of all
I have a situation where I have nested toggle statements in jQuery. I have
I have a number of tables, which have nested tables. I using jQuery to

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.