PSCmdlet dynamic auto complete a parameter (like Get-Process)
From MSDN: How to Declare Dynamic Parameters
Your Cmdlet
class must implement the IDynamicParameters
interface. This interface:
Provides a mechanism for a cmdlet to retrieve parameters that can be added dynamically by the Windows PowerShell runtime.
EDIT:
The IDynamicParameters.GetDynamicParameters()
method should:
return an object that has properties and fields with parameter related attributes similar to those define in a cmdlet class or a RuntimeDefinedParameterDictionary object.
If you look at this link, the author is doing this in PowerShell. He creates at runtime:
- a new instance of
ValidateSetAttribute
with a runtime array of possible values - He then creates a
RuntimeDefinedParameter
onto which he assigns theValidateSetAttribute
- He returns a
RuntimeDefinedParameterDictionary
containing this parameter
You can do the same in C#. Your GetDynamicParameters()
method should return this RuntimeDefinedParameterDictionary
containing the appropriate RuntimeDefinedParameter
.