I have this use case of manipulating Azure object JSON templates.
Take this example https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/201-site-to-site-vpn/azuredeploy.parameters.json which looks like
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminUsername": {
"value": "GEN-UNIQUE"
},
"localGatewayIpAddress": {
"value": "52.25.48.88"
},
"localAddressPrefix": {
"value": "10.0.0.0/24"
},
"azureVNetAddressPrefix": {
"value": "10.3.0.0/16"
},
"subnetPrefix": {
"value": "10.3.0.0/24"
},
"gatewaySubnetPrefix": {
"value": "10.3.200.0/29"
},
"sharedKey": {
"value": "GEN-UNIQUE"
},
"adminPasswordOrKey": {
"value": "GEN-SSH-PUB-KEY"
}
}
}
Now I can read it fine like this:
$Uri = 'https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/201-site-to-site-vpn/azuredeploy.parameters.json' $myParamterSet = Invoke-WebRequest $Uri | ConvertFrom-Json
and we can see the parameters like
$myParamterSet.parameters
adminUsername : @{value=GEN-UNIQUE}
localGatewayIpAddress : @{value=52.25.48.88}
localAddressPrefix : @{value=10.0.0.0/24}
azureVNetAddressPrefix : @{value=10.3.0.0/16}
subnetPrefix : @{value=10.3.0.0/24}
gatewaySubnetPrefix : @{value=10.3.200.0/29}
sharedKey : @{value=GEN-UNIQUE}
adminPasswordOrKey : @{value=GEN-SSH-PUB-KEY}
We can even change them like
PS C:\scripts> $myParamterSet.parameters.adminUsername.value = 'bla1'
PS C:\scripts> $myParamterSet.parameters
adminUsername : @{value=bla1}
localGatewayIpAddress : @{value=52.25.48.88}
localAddressPrefix : @{value=10.0.0.0/24}
azureVNetAddressPrefix : @{value=10.3.0.0/16}
subnetPrefix : @{value=10.3.0.0/24}
gatewaySubnetPrefix : @{value=10.3.200.0/29}
sharedKey : @{value=GEN-UNIQUE}
adminPasswordOrKey : @{value=GEN-SSH-PUB-KEY}
My question is how to add another parameter to this parameter set?
For example, I want to add
environment : @{value=dev}
Trying to add an element fails:
PS C:\scripts> $myParamterSet.parameters += [PSCustomObject]@{environment='dev'}
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
At line:1 char:1
+ $myParamterSet.parameters += [PSCustomObject]@{environment='dev'}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Get-Member shows that these parameters are PS Custom Objects:
PS C:\scripts> $myParamterSet.parameters | Get-Member
TypeName: System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
adminPasswordOrKey NoteProperty System.Management.Automation.PSCustomObject adminPasswordOrKey=@{value=GEN-SSH-PUB-KEY}
adminUsername NoteProperty System.Management.Automation.PSCustomObject adminUsername=@{value=bla1}
azureVNetAddressPrefix NoteProperty System.Management.Automation.PSCustomObject azureVNetAddressPrefix=@{value=10.3.0.0/16}
gatewaySubnetPrefix NoteProperty System.Management.Automation.PSCustomObject gatewaySubnetPrefix=@{value=10.3.200.0/29}
localAddressPrefix NoteProperty System.Management.Automation.PSCustomObject localAddressPrefix=@{value=10.0.0.0/24}
localGatewayIpAddress NoteProperty System.Management.Automation.PSCustomObject localGatewayIpAddress=@{value=52.25.48.88}
sharedKey NoteProperty System.Management.Automation.PSCustomObject sharedKey=@{value=GEN-UNIQUE}
subnetPrefix NoteProperty System.Management.Automation.PSCustomObject subnetPrefix=@{value=10.3.0.0/24}
How do I add one more?