Skip to content

Instantly share code, notes, and snippets.

@JeffBrownTech
Last active February 9, 2021 03:51
Show Gist options
  • Save JeffBrownTech/313692499afaabf0d0f3a3cd2f455f11 to your computer and use it in GitHub Desktop.
Save JeffBrownTech/313692499afaabf0d0f3a3cd2f455f11 to your computer and use it in GitHub Desktop.
PowerShell Dynamic Block Example
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