Last active
February 9, 2021 03:51
-
-
Save JeffBrownTech/313692499afaabf0d0f3a3cd2f455f11 to your computer and use it in GitHub Desktop.
PowerShell Dynamic Block Example
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
DynamicParam { | |
if ($ChannelType -eq 'Private') { | |
# Define parameter attributes | |
$paramAttributes = New-Object -Type System.Management.Automation.ParameterAttribute | |
$paramAttributes.Mandatory = $true | |
# Create collection of the attributes | |
$paramAttributesCollect = New-Object -Type ` | |
System.Collections.ObjectModel.Collection[System.Attribute] | |
$paramAttributesCollect.Add($paramAttributes) | |
# Create parameter with name, type, and attributes | |
$dynParam1 = New-Object -Type ` | |
System.Management.Automation.RuntimeDefinedParameter("PrivateChannelOwner", [string], | |
$paramAttributesCollect) | |
# Add parameter to parameter dictionary and return the object | |
$paramDictionary = New-Object ` | |
-Type System.Management.Automation.RuntimeDefinedParameterDictionary | |
$paramDictionary.Add("PrivateChannelOwner", $dynParam1) | |
return $paramDictionary | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment