我有一个Json文件作为配置文件,如下所示:
{
"managedApiConnections": {
"Testoffice365_Connection_1": {
"api": {
"id": "/subscriptions/.../office365"
},
"authentication": {
"type": "ManagedServiceIdentity"
},
"connection": {
"id": "/subscriptions/.../Test_Connection_1"
},
"connectionRuntimeUrl": "https://.../office365/xxx3501"
},
"Testsql_Connection_1": {
"api": {
"id": "/subscriptions/xxx/providers/Microsoft.Web/locations/eastasia/managedApis/sql"
},
"authentication": {
"type": "ManagedServiceIdentity"
},
"connection": {
"id": "/subscriptions/xxxx/resourceGroups/xxxx/providers/Microsoft.Web/connections/sql_SIT"
},
"connectionProperties": {
"authentication": {
"audience": "https://database.windows.net/",
"type": "ManagedServiceIdentity"
}
},
"connectionRuntimeUrl": "https://8xxxx.02.common.logic-eastasia.azure-apihub.net/apim/sql/xxxx1b"
}
},
"serviceProviderConnections": {
"Testblob_Connection_1": {
"displayName": "blobxxx",
"parameterSetName": "ManagedServiceIdentity",
"parameterValues": {
"authProvider": {
"Type": "ManagedServiceIdentity"
},
"blobStorageEndpoint": "@appsetting('blob_url_test')"
},
"serviceProvider": {
"id": "/serviceProviders/AzureBlob"
}
},
"Testsql_Connection_2": {
"displayName": "SQL_xxxx",
"parameterSetName": "ManagedServiceIdentity",
"parameterValues": {
"authProvider": {
"Type": "ManagedServiceIdentity"
},
"databaseName": "xxxx ",
"managedIdentityType": "SystemAssigned",
"serverName": "xxxx.database.windows.net"
},
"serviceProvider": {
"id": "/serviceProviders/sql"
}
}
}
}
Now,由于自动化的需要,为了满足新的连接实例,我需要在这个配置文件中添加额外的配置信息,比如添加新的O365连接,我需要add using powershell to get the content from below json template then add it Before the node 100:
{
"<APIConnectionName>_<DeployENV>": {
"api": {
"id": "/subscriptions/<subscriptionsID>/providers/Microsoft.Web/locations/eastasia/managedApis/office365"
},
"authentication": {
"type": "ManagedServiceIdentity"
},
"connection": {
"id": "/subscriptions/<subscriptionsID>/resourceGroups/<resourceGroups>/providers/Microsoft.Web/connections/<APIConnectionName>_<DeployENV>"
},
"connectionRuntimeUrl": "https://xxxx/office365/<connectionRuntimeUrl>"
}
}
注意:将模板添加到Json文件时,不需要outermost braces.
如何使用Powershell脚本来实现它?