February 2019
Intermediate to advanced
626 pages
15h 51m
English
Dynamic parameters must be accessed using the PSBoundParameters variable within a function or script; dynamic parameters do not initialize variables of their own.
The value of the Action parameter used in the previous examples must be retrieved by using Action as a key, shown as follows:
using namespace System.Management.Automationfunction Test-DynamicParam { [CmdletBinding()] param ( ) dynamicparam { $paramDictionary = [RuntimeDefinedParameterDictionary]::new() $parameter = [RuntimeDefinedParameter]::new('Action', [String], [Attribute[]]@( [Parameter]@{ Mandatory = $true; Position = 1 } [ValidateSet]::new('Start', 'Stop', 'Create', 'Delete') ) ) $paramDictionary.Add($parameter.Name, $parameter) $paramDictionaryRead now
Unlock full access