Skip to content

Instantly share code, notes, and snippets.

@stuartleeks
Created January 14, 2016 21:05
Show Gist options
  • Save stuartleeks/7ff7973dc820684d1038 to your computer and use it in GitHub Desktop.
Save stuartleeks/7ff7973dc820684d1038 to your computer and use it in GitHub Desktop.
Generate parameters for Azure Resource Manager template
param(
$templateFile,
[switch] $includeParametersWithDefaults
)
$template = Get-Content $templateFile | ConvertFrom-Json
function getDefaultValue($type){
switch ($type){
"bool" {'false'}
"int" {0}
"array" {'[]'}
"object" {'{}'}
default {'""'}
}
}
'{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {'
$separator = ""
$template.parameters.psobject.Properties `
| ?{
($includeParametersWithDefaults) -or ($_.Value.defaultValue -eq $null)
}`
| %{
$type = $_.Value.type
if ($_.Value.defaultValue -eq $null){
$value = getDefaultValue $type
} else {
$value = ConvertTo-Json $_.Value.defaultValue
}
" $separator`"$($_.Name)`": {
`"value`": $value
}"
}
' }
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment