Functions/New-ARMfunction.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
function New-ARMfunction { [cmdletbinding()] Param( #[Parameter(ParameterSetName='concat')] [switch]$ConCat , #[Parameter(ParameterSetName='concat')] [string[]]$Values ) DynamicParam { $Dictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary $NewDynParam = @{ Name = "Variable" Mandatory = $false ValueFromPipelineByPropertyName = $true ValueFromPipeline = $false DPDictionary = $Dictionary } #ParameterSetName = "__AllParameterSets" #ParameterSetName = "ByVariable" $allVars = $script:Template.variables.Keys if ($allVars) { $null = $NewDynParam.Add("ValidateSet",$allVars) } else { $null = $NewDynParam.Add("ValidateSet",@("-")) } New-DynamicParam @NewDynParam $NewDynParam.Name = "Parameter" #$NewDynParam.ParameterSetName = "ByParam" $allParams = $script:Template.parameters.Keys if (($allParams | Measure-Object).Count -eq 1) { $allParams = @(,$allParams) } if ($allParams) { $NewDynParam.ValidateSet = $allParams } else { $NewDynParam.ValidateSet = @("empty","box") } New-DynamicParam @NewDynParam #$Dictionary | ConvertTo-Json | out-file -FilePath c:\temp\dyn.json -Encoding utf8 -Append $Dictionary } Begin { $f = $MyInvocation.InvocationName throw "$f is not implemented" } Process { $var = $PSBoundParameters.Variable $param = $PSBoundParameters.Parameter $hashKeyIndex = [ordered]@{} $index = 0 foreach ($key in $PSBoundParameters.Keys) { $hashKeyIndex.Add($key,$index) $index++ } if ($ConCat) { $ConcatValue = "[concat('" if ($Values) { return "$ConcatValue$($Values -join "','")))]" } if ($var -and $param) { $ConcatValue = "[concat(" $varValue = "variable('$var')" $paramValue = "parameter('$param')" $paramIndex = $hashKeyIndex.Parameter $varIndex = $hashKeyIndex.Variable if ($paramIndex -lt $varIndex) { return "$ConcatValue" + "$paramValue," + "$varValue" + ")]" } if ($varIndex -lt $paramIndex) { return "$ConcatValue" + "$varValue," + "$paramValue" + "')]" } } } } } |