function parameters RRS feed

  • Question

  • I'm probably going the wrong way but I'm writing a function that apart from other things I'd like to list some set values similarly like get-module -ListAvailable does so it doesn't expect any input it just prints a list. Not sure what type of parameter would that be for this case and whether it would even be a parameter. When I looked in get-module description it doesn't mention what type is -listAvailable.


    Monday, March 30, 2020 1:21 PM

All replies

  • help get-module -online

    It clearly states the parameter type but you have to actually read the help.

    I recommend learning how to use help.  Your statement shows that you don't know how to use it.

    run the following and read ALL of it carefully.

    help help


    Monday, March 30, 2020 1:32 PM
  • I Actually tried [Switch] but was getting error saying that powershell cannot convert System.Object  to System.Management.Automation.SwichParameter so thought I'm going the wrong way. My actual variable holding the list of items is a System.String.


    Monday, March 30, 2020 1:48 PM
  • I follow - Also interested in the answers - thanks !
    Monday, March 30, 2020 1:50 PM
  • I follow - Also interested in the answers - thanks !

    Read the help.  It is right in front of you.

    To use Power5shell you must learn how to read the help.  You do not know how to do that.  

    Type the following:

    help help

    and read all of what you see.


    Monday, March 30, 2020 3:04 PM
  • It's not that hard.

    function FunctionName {
        param (
        if ($ListAvailable){
            # do something here
            # do something else here
    FunctionName -ListAvailable

    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Monday, March 30, 2020 3:15 PM
  • Without doing [String]$ListAvailable it wouldn't work for me throwing the error mentioned earlier. Above very nicely explained what is actually needed in the code for the switch parameter to work. Thank you. 


    Monday, March 30, 2020 3:38 PM