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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:46:02+00:00 2026-05-16T22:46:02+00:00

I am using switch parameters in my PowerShell script in this fashion. param( [switch]

  • 0

I am using switch parameters in my PowerShell script in this fashion.

param(
    [switch] $Word,
    [switch] $Excel,
    [switch] $powerpoint,
    [switch] $v2007,
    [switch] $v2010,
    [switch] $x86,
    [switch] $x64,
)

I am trying to figure out any neat way to have it more enum style.
As anyone might guess, I would want the user to choose between word, excel and powerpoint.
And between x2007 and v2010.

Is there a neat way to get input params enum style?

I am new to PowerShell. So if this sounds like that I don’t know something obvious, then please point me to some link where I can read about it.

  • 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-16T22:46:02+00:00Added an answer on May 16, 2026 at 10:46 pm

    I would use a ValidateSet parameter attribute instead.

    From: about_Functions_Advanced_Parameters

    The ValidateSet attribute specifies a set of valid values for a
    parameter or variable. Windows PowerShell generates an error if a
    parameter or variable value does not match a value in the set.

    Example function:

    function test-value
    {
        param(
            [Parameter(Position=0)]
            [ValidateSet('word','excel','powerpoint')]
            [System.String]$Application,
    
            [Parameter(Position=1)]
            [ValidateSet('v2007','v2010')]
            [System.String]$Version
        )
    
    
        write-host "Application: $Application"
        write-host "Version: $Version"
    }   
    
    
    PS > test-value -application foo
    

    Output:

    test-value : Cannot validate argument on parameter 'Application'. The argument "foo" does not belong to the set "word,excel,powerpoint" specified by the ValidateSet attribute. Supply an argument that is in the set and then try the command again.

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

Sidebar

Related Questions

I have this powershell script named testSwitch.ps1: param( [switch] $s ) Return 's= '
When executing a Powershell script (in 2.0) using the -File command line switch, and
I'm programming some C code using gcc -std=C89 switch on a Linux box. This
I'm currently using the excellent mobile detection script from: detectmobilebrowsers.mobi This works really well
I am using this function to switch between views in Xcode 4.3. [self performSegueWithIdentifier:@NextView
How to write following statement in c using switch statement in c int i
I am using a switch-statement to switch between modes on a the jqPlot jQuery
I'm programming a simple text-based RPG using a switch statement for a game loop.
Im really trying to keep my code clean by using the switch statement but
Using QStackedWidget to switch between the views, I will be able to traverse between

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.