Parameters, Static vs Dynamic

Welcome Forums General PowerShell Q&A Parameters, Static vs Dynamic

This topic contains 3 replies, has 3 voices, and was last updated by

 
Member
3 years, 6 months ago.

  • Author
    Posts
  • #25803

    Participant
    Points: 1
    Rank: Member

    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

    Participant
    Points: 303
    Helping Hand
    Rank: Contributor

    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

    Participant
    Points: 1
    Rank: Member

    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 {
    [CmdletBinding()]
    param(
    [Parameter(Mandatory=$True,Position=1]
    [String]$targetmachine,
    [Parameter(Mandatory=$True,Position=2]
    [ValidateSet(Get-ChildItem -Path \\server\me-backups\_Installs\_AutoInstall\ -Directory | Select-Object -ExpandProperty Name)]
    [String]$meversion
    )

  • #25808

    Member
    Points: 0
    Rank: Member

    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.

The topic ‘Parameters, Static vs Dynamic’ is closed to new replies.