checking which parameter selected

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Daniel Krebs Daniel Krebs 2 months, 3 weeks ago.

  • Author
    Posts
  • #65721
    Profile photo of Idan
    Idan
    Participant

    hi
    i have a script that has several parameters.
    A user selects a parameter and gives it a value.
    When parameter is selected a certain cmdlet is being called.
    each parameter has different a action.

    currently i'm using an IF statement for each parameter to check if it was selected.
    is there a better way to check which parameter is selected?
    also, i want a "default" cmdlet to take place when no parameter (they're not mandatory) is selected, is there a nice way to check this too?

  • #65728
    Profile photo of Dan Potter
    Dan Potter
    Participant

    function get-selectedparams{

    param($one,$two,$three)

    $PSBoundParameters

    }

  • #65745
    Profile photo of Daniel Krebs
    Daniel Krebs
    Moderator

    Idan,

    The following short post gives a quick explanation of $PSBoundParameters.

  • #65752
    Profile photo of Idan
    Idan
    Participant

    Thank you Daniel for the link.
    this is basically what i did in my script.
    I was just wondering if maybe there is a better way to work with the parameter selection besides using if statement for each one.

  • #65761
    Profile photo of Daniel Krebs
    Daniel Krebs
    Moderator

    Apologies, I didn't read your original post fully because I wanted to add context to Dan's reply.

    An alternative way to test for parameters is using parameter sets which would give you an idea for your question regarding defaults.

    Here are some links as reference:

You must be logged in to reply to this topic.