Function Dynamic Parameter

Hello Everyone,

Is it possible to create a dynamic parameter that is generated from a command output?

Today I have a function that would pull a list of vCenters from our backup application via API. If possible, I would like my function to disable/enable backups on one of the vCenters that was generated from my get-vcenters function to be the list of my validated set in my execute-maintenance function.

Example:
get-vcenters function returns a list of vCenter name

execute-maintenance -action <disableBackups/enableBackups> -vCenter <output_from_get-vcenters>

My end goal is to have a list of vCenters that will automatically be updated, and remove the need to have to constantly update the CSV list of vCenters in the script.

Hi, welcome to the forum :wave:

If you’ve searched online for a solution to this I suspect you’ve not yet found what you’re looking for because your search term is wrong :slight_smile:

Rather than dynamic parameters, what you’re looking for is argument completion. In PowerShell dynamic parameters is a term used to describe parameters that are only available under certain conditions.

There are several techniques to achieve this - the first link is more to the point, but the second gives a good overview of the different techniques and their limitations.

https://powershell.one/powershell-internals/attributes/auto-completion

1 Like