Monday, January 6, 2020

Extract Data from JSON file Using PowerShell

Here is my requirement...

I have a JSON File as below and I need to read the Parameter value from the JSON file.
I need to assign that parameter value to Azure Key Vault as Secret.


Sample JSON:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "factoryName": {
            "value": "TestADF"
        },
        "KeyVaulturl": {
            "value": "https://existinglcskeyvalut.vault.azure.net/"
        }
    }
}


And File Located in D:\SampleFiles\TestFile.json



Step 1:

Open Powershell Window as Administrator


Step 2:

$JSONData= (Get-Content -Raw -Path 'D:\SampleFiles\TestFile.json' | ConvertFrom-Json).parameters.KeyVaulturl.Value
$JSONDataKey=ConvertTo-SecureString $JSONData -AsPlainText -Force
Set-AzureKeyVaultSecret –VaultName 'YourkeyVaultName' –Name ‘SecretName’ -SecretValue $JSONDataKey














No comments:

Post a Comment

Activating All triggers in ADF using powershell

Scenario: I have an ADF having more than one pipelines. For each pipeline more than one triggers. I need to activate all the triggers i...