Удалите нежелательный контент из шаблона ARM (.json) с помощью powershell - PullRequest
0 голосов
/ 08 ноября 2018

AM пытается переопределить некоторое содержимое (пары значений) шаблона ARM (.json), выбирая значения из другого json, но как только пары значений из исходного файла завершены, я хотел бы удалить ненужные пары значений из файла назначения. . как мне это сделать.

Любая помощь по этому вопросу действительно необходима.

Мой пример кода

for($i=0;$i -lt $Getinputfilecontent.Schema.Count;$i++)
{
    $individualstructure[$i].name = $Getinputfilecontent.Schema[$i].name
    $individualstructure[$i].type = $Getinputfilecontent.Schema[$i].type
    $Getjsonfilecontent | ConvertTo-Json  -Depth 100 | % { 
[System.Text.RegularExpressions.Regex]::Unescape($_) } | set-content 
'C:\Scripts\CreateADF-Datasets\arm_template.json'
} 

Шаблон ARM, который переопределяется

{
    "name": "[concat(parameters('factoryName'), '/Veh_Obj')]",
    "type": "Microsoft.DataFactory/factories/datasets",
    "apiVersion": "2018-06-01",
    "properties": {
        "linkedServiceName": {
            "referenceName": "AzureDataLakeStore1",
            "type": "LinkedServiceReference"
        },
        "annotations": [],
        "type": "AzureDataLakeStoreFile",
        "structure": [
            {
                "name": "TBL_ID",
                "type": "int"
            },
            {
                "name": "SYS_ADD_DATE",
                "type": "date"
            },
            {
                "name": "SYS_CHG_DATE",
                "type": "date"
            },
            {
                "name": "CODE",
                "type": "string"
            },
            {
                "name": "Need to remove this value pair",
                "type": "Need to remove this value pair"
            },
            {
                "name": "Need to remove this value pair",
                "type": "Need to remove this value pair"
            },
            {
                "name": "Need to remove this value pair",
                "type": "Need to remove this value pair"
            },
            {
                "name": "Need to remove this value pair",
                "type": "Need to remove this value pair"
            },
            {
                "name": "Need to remove this value pair",
                "type": "Need to remove this value pair"
            },
            {
                "name": "Need to remove this value pair",
                "type": "Need to remove this value pair"
            },
            {
                "name": "Need to remove this value pair",
                "type": "Need to remove this value pair"
            },
            {
                "name": "Need to remove this value pair",
                "type": "Need to remove this value pair"
            },
            {
                "name": "Need to remove this value pair",
                "type": "Need to remove this value pair"
            },
            {
                "name": "Need to remove this value pair",
                "type": "Need to remove this value pair"
            },
            {
                "name": "Need to remove this value pair",
                "type": "Need to remove this value pair"
            },
            {
                "name": "Need to remove this value pair",
                "type": "Need to remove this value pair"
            }
        ],
        "typeProperties": {
            "format": {
                "type": "TextFormat",
                "columnDelimiter": "|",
                "rowDelimiter": "",
                "quoteChar": "\"",
                "nullValue": "\"\"",
                "encodingName": null,
                "treatEmptyAsNull": true,
                "skipLineCount": 0,
                "firstRowAsHeader": false
            },
            "fileName": "[parameters('Veh_Obj_properties_typeProperties_fileName')]",
            "folderPath": "[parameters('Veh_Obj_properties_typeProperties_folderPath')]"
        }
    },
    "dependsOn": [
        "[concat(variables('factoryId'), '/linkedServices/AzureDataLakeStore1')]"
    ]
}

1 Ответ

0 голосов
/ 08 ноября 2018

Импортируйте его в powershell:

$q = Get-Content .\path to json | Convertfrom-Json

и отредактируйте его:

$q.properties.structure = $q.properties.structure.where{$_.name -notmatch '^need' }
...