Created
July 5, 2017 00:45
-
-
Save sdurandeu/5190b8c3ac0459e291abbb2e6aa3cc55 to your computer and use it in GitHub Desktop.
Powershell: Manipulate a Json Configuration File
This file contains hidden or 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
| # read configuration file | |
| $configuration = Get-Content -Raw -Path $parametersFilePath | ConvertFrom-Json | |
| # generate intermediate ARM template parameters file with serialized JSON settings | |
| $armParametersFile = @{ | |
| "`$schema" = "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#"; | |
| "contentVersion" = "1.0.0.0"; | |
| "parameters" = New-Object psobject; | |
| } | |
| # transform properties with the { Value = "a-value" } subobject required by the arm template | |
| $configuration.ArmParameters.PSObject.Properties | foreach-object { $armParametersFile.parameters | Add-Member -Name $_.Name -Value @{ value = $_.Value } -MemberType NoteProperty } | |
| # serialize LocationSettingsJson and AzureCdnDomainsPostfixJson to json | |
| $locations = ($configuration.Locations | Select-Object -ExpandProperty Settings) | |
| $armParametersFile.parameters | Add-Member -Name "LocationSettingsJson" -Value @{ value = (ConvertTo-Json $locations -Compress) } -MemberType NoteProperty | |
| $armParametersFile.parameters | Add-Member -Name "AzureCdnDomainsPostfixJson" -Value @{ value = (ConvertTo-Json $configuration.AzureCdnDomainsPostfix -Compress) } -MemberType NoteProperty | |
| # save arm template parameters file | |
| $armParametersFile | ConvertTo-Json -depth 10 | Set-Content $parametersTempFilePath | |
| # sign in |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment