Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jbruett/20fc8bdc5680c922bcda168dfb5637d2 to your computer and use it in GitHub Desktop.

Select an option

Save jbruett/20fc8bdc5680c922bcda168dfb5637d2 to your computer and use it in GitHub Desktop.

Revisions

  1. jbruett created this gist Apr 5, 2018.
    24 changes: 24 additions & 0 deletions AwsRegionDynamicParameterPowershell.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    "AWS_Region_Dynamic_Param": {
    "prefix": "aws_region",
    "body": [
    "DynamicParam {",
    "\t$ParamDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary",
    "\t$CR_ParamName = 'Region'",
    "\t$CR_AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]",
    "\t$CR_Attribute = New-Object System.Management.Automation.ParameterAttribute",
    "\t$CR_Attribute.HelpMessage = 'List all the regions to be included in the document'",
    "\t$CR_Attribute.Mandatory = $true",
    "\t$CR_Attribute.ValueFromPipelineByPropertyName = $true",
    "\t$CR_AttributeCollection.add($CR_Attribute)",
    "\t$CR_intRegions = Get-AWSRegion -IncludeChina | Select-Object -ExpandProperty Region",
    "\t$CR_intRegions += Get-AWSRegion -IncludeGovCloud | Select-Object -ExpandProperty Region",
    "\t$CR_intRegions = $CR_intRegions | Select-Object -Unique",
    "\t$CR_ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($CR_intRegions)",
    "\t$CR_AttributeCollection.add($CR_ValidateSetAttribute)",
    "\t$CR_Param = New-Object System.Management.Automation.RuntimeDefinedParameter($CR_ParamName, [String[]],$CR_AttributeCollection)",
    "\t$ParamDictionary.Add($CR_ParamName, $CR_Param)",
    "\treturn $paramDictionary",
    "\t}"
    ],
    "description": "A dynamic parameter that builds a list of AWS regions, requires"
    }