Parameters, Static vs Dynamic

This topic contains 3 replies, has 3 voices, and was last updated by  Dave Wyatt 2 years, 11 months ago.

  • Author
  • #25803


    I have two questions.

    1. Is it possible to have a dynamic parameter's .Parameter help context appear in get-help?

    2. Similar question in having the "syntax" portion of get-help to show a dynamic parameter?

    Love this community!

  • #25804

    Rob Simmers

    Dynamic parameters do not show in help or syntax because they are processed at runtime. Depending on what you are trying to accomplish, you can use Parameter Sets. Basically, if you use a -Foo switch then add or remove available parameters passed to a function. It would be easier to provide a scenario and expected results so that advice can be given specifically on your goal(s).

  • #25806


    Perhaps converting to a static variable will be easier so that documentation is possible.

    I'd like to have the $meversion parameters ValidateSet property set to the results of the following (if the folder list changes, the validate set changes):
    –> $arrSet = Get-ChildItem -Path \\server\me-backups\_Installs\_AutoInstall\ -Directory | Select-Object -ExpandProperty Name

    I'll write it as I think of it, then hopefully the result can be crafted as a static parameters vs. using a dynamic one.

    function install-me {
    [ValidateSet(Get-ChildItem -Path \\server\me-backups\_Installs\_AutoInstall\ -Directory | Select-Object -ExpandProperty Name)]

  • #25808

    Dave Wyatt

    You may be able to do this if you switch to XML help files. Comment-based help definitely won't work here, but XML files are pretty much displayed as-is.

You must be logged in to reply to this topic.