Skip to content

Commit c33fcda

Browse files
authored
Community Snippet - AWSRegionDynamicParameter
adds a dynamic parameter of the current AWS regions
1 parent ab5ee30 commit c33fcda

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

docs/community_snippets.md

+34
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,47 @@ _To contribute, check out our [guide here](#contributing)._
1616

1717
| Table of Contents |
1818
|:------------------|
19+
| [AWSRegionDynamicParameter](#awsregiondynamicparameter): _Creates a dynamic parameter of current AWS regions by @jbruett_ |
1920
| [CalculatedProperty](#calculatedproperty): _Create a calculated property for use in a select-object call by @corbob_ |
2021
| [DateTimeWriteVerbose](#datetimewriteverbose): _Write-Verbose with the time and date pre-pended to your message by @ThmsRynr_ |
2122
| [Parameter-Credential](#parameter-credential): _Add a standard credential parameter to your function by @omniomi_ |
2223
| [PSCustomObject](#pscustomobject): _A simple PSCustomObject by @brettmillerb_ |
2324

2425
## Snippets
2526

27+
### AWSRegionDynamicParameter
28+
29+
Creates a dynamic parameter of the current AWS regions. Includes parameter validation.
30+
31+
#### Snippet
32+
33+
```json
34+
"AWSRegionDynamicParam": {
35+
"prefix": "aws_region",
36+
"body": [
37+
"DynamicParam {",
38+
"\t$ParamDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary",
39+
"\t$CR_ParamName = 'Region'",
40+
"\t$CR_AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]",
41+
"\t$CR_Attribute = New-Object System.Management.Automation.ParameterAttribute",
42+
"\t$CR_Attribute.HelpMessage = 'List all the regions to be included in the document'",
43+
"\t$CR_Attribute.Mandatory = $true",
44+
"\t$CR_Attribute.ValueFromPipelineByPropertyName = $true",
45+
"\t$CR_AttributeCollection.add($CR_Attribute)",
46+
"\t$CR_intRegions = Get-AWSRegion -IncludeChina | Select-Object -ExpandProperty Region",
47+
"\t$CR_intRegions += Get-AWSRegion -IncludeGovCloud | Select-Object -ExpandProperty Region",
48+
"\t$CR_intRegions = $CR_intRegions | Select-Object -Unique",
49+
"\t$CR_ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($CR_intRegions)",
50+
"\t$CR_AttributeCollection.add($CR_ValidateSetAttribute)",
51+
"\t$CR_Param = New-Object System.Management.Automation.RuntimeDefinedParameter($CR_ParamName, [String[]],$CR_AttributeCollection)",
52+
"\t$ParamDictionary.Add($CR_ParamName, $CR_Param)",
53+
"\treturn $paramDictionary",
54+
"\t}"
55+
],
56+
"description": "A dynamic parameter that builds a list of AWS regions"
57+
}
58+
```
59+
2660
### CalculatedProperty
2761

2862
Create calculated property for use in Select Statements

0 commit comments

Comments
 (0)