February 2019
Intermediate to advanced
626 pages
15h 51m
English
One possible use of dynamic parameters is to change validation based on the value supplied for another parameter. Another use is to change which parameters are available, again based on the value of another parameter.
The following example changes validValues into ValidateSet depending on the value supplied for the Type parameter:
using namespace System.Management.Automationfunction Test-DynamicParam { [CmdletBinding()] param ( [Parameter(Mandatory, Position = 1)] [ValidateSet('Service', 'Process')] [String]$Type, [Parameter(Mandatory, Position = 3)] [String]$Name ) dynamicparam { $paramDictionary = [RuntimeDefinedParameterDictionary]::new() [String[]]$validValues = switch ($Type) { 'Service' { 'Get', 'Start', 'Stop', ...Read now
Unlock full access