ps/Modules/Cole.PowerShell.Developer/Public/Get-DynamicAwsRegionParameter.ps1

36 lines
1.5 KiB
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
function Get-DynamicAwsRegionParameter {
[CmdletBinding()]
param(
[Parameter(Mandatory = $false)]
[string]$GeneratedParameterName = "Region",
[Parameter(Mandatory = $false)]
[string]$ParameterSetName = "__AllParameterSets",
[Parameter(Mandatory = $false)]
[switch]$IsMandatoryParameter
)
# Define the Paramater Attributes
$ParameterName = $GeneratedParameterName
$RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
$AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
$ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
$ParameterAttribute.Mandatory = $IsMandatoryParameter
$ParameterAttribute.ParameterSetName = $ParameterSetName
$ParameterAttribute.HelpMessage = "The AWS Region to Use for Requests"
$AttributeCollection.Add($ParameterAttribute)
# Generate and add the ValidateSet
$arrSet = Get-SupportedAwsRegions
$ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet)
$AttributeCollection.Add($ValidateSetAttribute)
# Create the dynamic parameter
$RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string[]], $AttributeCollection)
$RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter)
return $RuntimeParameterDictionary
}