-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding PSCafnaming community session
- Loading branch information
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
JanOehenRyanBartram/GenerateAndValidateYourResourceNames/demo.ps1
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import-module ./src/pscafnaming.psd1 -Force | ||
|
||
|
||
|
||
|
||
|
||
New-CAFResourceName -Name test -Prefixes psconf, prod -Suffixes 001 -ResourceType 'storage account' -Separator 1 | ||
|
||
|
||
|
||
|
||
New-CAFResourceName -IgnoreValidations -ResourceType 'storage account' -Prefixes a, b -Suffixes y, z -CleanInput $false | ||
|
||
|
||
|
||
|
||
New-CAFResourceName -name 'mysupercool---storageaccount' -ResourceType 'storage account' -CleanInput $false -AddResourceAbbreviation $false -Separator | ||
|
||
Update-CAFOnlineResourceDefinitions | ||
|
||
|
||
|
||
|
||
function New-VerySpecificCompanyNamingConventionThatHasBeenThoughtOutVeryWellAndTook2YearsToDecide { | ||
param( | ||
[parameter(Mandatory)] | ||
[ValidateLength(3)] | ||
[string] | ||
$Project, | ||
|
||
[parameter(Mandatory)] | ||
[ValidateSet('Dev', 'UAT', 'Prod')] | ||
[string] | ||
$Environment, | ||
|
||
[parameter(Mandatory)] | ||
[int32] | ||
$Count, | ||
|
||
[parameter(Mandatory)] | ||
[int32] | ||
$IdSeed | ||
) | ||
|
||
DynamicParam { | ||
# Set the dynamic parameter for Resource Types | ||
$ParameterName = 'ResourceType' | ||
|
||
# Create the dictionary | ||
$RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary | ||
|
||
# Create the collection of attributes | ||
$AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] | ||
|
||
$ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute | ||
$ParameterAttribute.Mandatory = $true | ||
|
||
# Add the attributes to the attributes collection | ||
$AttributeCollection.Add($ParameterAttribute) | ||
|
||
# Generate and set the ValidateSet | ||
$arrSet = Get-CAFUniqueResources | ||
$ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($arrSet) | ||
|
||
# Add the ValidateSet to the attributes collection | ||
$AttributeCollection.Add($ValidateSetAttribute) | ||
|
||
# Create and return the dynamic parameter | ||
$RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($ParameterName, [string], $AttributeCollection) | ||
$RuntimeParameterDictionary.Add($ParameterName, $RuntimeParameter) | ||
return $RuntimeParameterDictionary | ||
} | ||
|
||
process { | ||
$i = -1 | ||
while ($IdSeed + ++$i) { | ||
$index = IdSeed + $i | ||
New-CAFResourceName -Name $Project -Prefixes 'psconf', $Environment -Suffixes $index -ResourceType $PSBoundParameters["ResourceType"] | ||
} | ||
} | ||
} |