简体   繁体   中英

How to assign json file's content to a variable using powershell

I trying to run below PowerShell script to add azure data factory data sets. But im getting motioned error. Json File

{
    "name": "DSNAME",
    "properties": {
        "linkedServiceName": {
            "referenceName": "REGNAME1",
            "type": "LinkedServiceReference"
        },
        "annotations": [],
        "type": "AzureDataExplorerTable",
        "schema": [],
        "typeProperties": {
            "table": "TABLE_TEST"
        }
    },
    "type": "Microsoft.DataFactory/factories/datasets"
}

Powershell

az config set extension.use_dynamic_install=yes_without_prompt
Get-ChildItem "ADF_DATASETS/" -Filter *.json | 
Foreach-Object {
    $content = Get-Content $_.FullName

az datafactory dataset create --properties $content --name "DATASETNAME" --factory-name "ADFNAME" --resource-group "RG_TEST"

}

Error: Error detail: Expecting property name enclosed in double quotes: line 1 column 2 (char 1) Please provide a valid JSON file path or JSON string. The provided JSON string may have been parsed by the shell. See https://docs.microsoft.com/cli/azure/use-cli-effectively#use-quotation-marks-in-arguments ERROR: Failed to parse string as JSON:

What kind of text --properties expect?

It is expecting JSON string in double quotation marks . So you have to put the value of $content inside the double quotation mark.

az datafactory dataset create --properties "{\"type\":\"AzureBlob\",\"linkedServiceName\":{\"type\":\"LinkedServiceReference\",\"referenceName\":\"exampleLinkedService\"},\"parameters\":{\"MyFileName\":{\"type\":\"String\"},\"MyFolderPath\":{\"type\":\"String\"}},\"typeProperties\":{\"format\":{\"type\":\"TextFormat\"},\"fileName\":{\"type\":\"Expression\",\"value\":\"@dataset().MyFileName\"},\"folderPath\":{\"type\":\"Expression\",\"value\":\"@dataset().MyFolderPath\"}}}" --name "exampleDataset" --factory-name "exampleFactoryName" --resource-group "exampleResourceGroup"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM