{
"$schema": "a",
"contentVersion": "b",
"extensions": [
{
"Name": "c",
"Type": "d",
"Version": "e",
"ConnectionProperties": {
"MaxExecutionTime": "f",
"Authentication": {
"Type": "g",
"Reference": {
"Provider": "h",
"Parameters": {
"SecretId": "i"
}
},
"Properties": {
"ApplicationId": "j",
"TenantId": "k"
}
}
},
"payloadProperties": {
"ConnectionString": {
"Value": "l"
},
"KqlSasUri": {
"reference": {
"path": "m",
"enableScopeTagBindings": "n"
}
},
"DatabaseName": {
"Value": "o"
}
},
"repeatOver": [
{
"name": "p",
"file": "q",
"database": "r"
}
]
}
]
}
Above is the json file, I wish to append to repeatOver array using powershell script
$getContentfromDestinationJson = Get-Content $pathToDestinationJson -Raw | ConvertFrom-Json
$destinationExtension = $getContentfromDestinationJson.extensions
Write-Host $destinationExtension
Output is --
@{Name=a; Type=b; Version=c; ConnectionProperties=; payloadProperties=; repeatOver=System.Object[]}
Also, when I try to write append to this repeatOver array in this json.
Note- the below code is in a for loop, I want to append this multiple times to the array..
for ($i=0; $i -le 3; $i++) {
$toWrite= [PSCustomObject]@{
name = 'd'
file = 'e'
database = 'f'
}
$destinationExtension.repeatOver += (ConvertTo-Json -InputObject $toWrite -Depth 3)
}
I see this error :
Method invocation failed because [System.Management.Automation.PSObject] does not contain a method named 'op_Addition'.
Also, how do I skip adding a $toWrite value if it already exists, by comparing the name field?