Last active
August 29, 2015 14:19
-
-
Save mattmcnabb/d973f1ed11902d46b340 to your computer and use it in GitHub Desktop.
Powershell Conditional Dynamic Parameters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Test-ConditionalParameter | |
{ | |
param | |
( | |
[validateset('Value1','Value2')] | |
[parameter()] | |
$Parameter1 | |
) | |
dynamicparam | |
{ | |
if ($PSBoundParameters.Parameter1 -eq 'Value1') | |
{ | |
$Dictionary = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameterDictionary | |
$ParamAttr = New-Object -TypeName System.Management.Automation.ParameterAttribute | |
$AttributeCollection = New-Object -TypeName 'Collections.ObjectModel.Collection[System.Attribute]' | |
$AttributeCollection.Add($ParamAttr) | |
$Parameter = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter -ArgumentList @('Parameter2', [string], $AttributeCollection) | |
$Dictionary.Add('Parameter2', $Parameter) | |
return $Dictionary | |
} | |
} | |
process {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment