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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:15:55+00:00 2026-06-10T01:15:55+00:00

Using c# to write a PowerShell cmdlet that has several parameter sets. Is there

  • 0

Using c# to write a PowerShell cmdlet that has several parameter sets.

Is there a parameter Type that can be used to qualify/select the required set?

For instance suppose I have these sets of parameters for a Create-IceCream cmdlet:

Create-IceCream [-Choco] .. <insert Choco specific parameters here>

Create-IceCream [-Cherry] .. <insert Cherry specific parameters here>

Create-IceCream .. <insert plain specific parameters here>

What would be the Type for parameters “Choco” and “Cherry”? Obviously a SwitchParameter type can’t be used since it can still be specified with $false value.

An Enum type would not be so intuitive and will require me to create many dynamic parameters.

Any ideas? And I probably should’ve mentioned that for this question let’s assume I’m restricted to creating one cmdlet only.

Thanks,

  • 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-10T01:15:56+00:00Added an answer on June 10, 2026 at 1:15 am

    If you have parameters that are truly unique between sets, then you don’t need a “selector” parameter at all. The “operable” params specified will determine the set on their own. This is the recommended approach, and the way most cmdlets work.

    Sometimes it does make it a bit clearer for the user to provide such a parameter, though. Switch is your best option for this, despite your worries. ParameterSets work entirely by the existence of parameters, they are totally ignorant of the value of any specified params. As such, there is no totally perfect option of any type. Switch provides the simplest interface available.

    Users have to be trying pretty hard to mess this up by passing -Choco:$false, considering the 99% usage of switch parameters is simple present/not-present. And powershell will enforce the parameterset either way, so it’s not possible to pass both -Choco:$false -Cherry:$true.

    In my experience, very few users even realize you can pass an explicit value to a Switch, and those who do tend to be more experienced and wouldn’t make that kind of mistake anyway.

    Edit

    Another option is to have a single -IceCreamType parameter which takes either an Enum or a string with ValidateSet. It can be a mandatory parameter that is part of all parametersets. Then internally you can interpret remaining shared args as needed. Powershell will complain, however, if it can’t figure out the parameter set based on the args passed, so there is some danger with this approach. You could work around with a DefaultParameterSetName, but after all of this you are starting to lose the value of using parametersets in the first place.

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

Sidebar

Related Questions

I am developing a Powershell Cmdlet using C#, and I was wondering if there's
I am trying to write a PowerShell script that can get pipeline input (and
Trying to write a PowerShell cmdlet that will mute the sound at start, unless
I wrote several Powershell scripts which deploy software for a client. I used Write-Host
I'm using Powershell on Windows XP and am trying to write a command that
I'm using read/write locks on Linux and I've found that trying to upgrade a
I am using to write a select query and the value for like statement
In C#, how many classes can you inherit from? When you write: using System.Web.UI;
I am trying to write a powershell script that will take in a text
Using PowerShell I can get the directories with the following command: Get-ChildItem -Path $path

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.