Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The PowerShell script is not producing the anticipated JSON output as intended

powershell script not working as expected

I am trying to achieve below format output with my PowerShell script.
Expected Output:

"TestParam": {
    "5903-95856-24869-e43": {
         "CallerName": "testparner",
         "ClientId": "123-45-789",
         "ClientSecret": {
             "KeyVaultSecretName": "ClientSecret"
          }
     }
}

Script I am using

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$PartnerName="testparner"
$ClientID="123-45-789"
$DM=@{
    "5903-95856-24869-e43"=@{
        "CallerName"= $PartnerName
        "ClientId"= $ClientID
        "ClientSecret"= @{
            "KeyVaultSecretName"= "ClientSecret"
        }
    }
}
$jsonData = @{
    "TestParam"= $DM
}
$jsonString = $jsonData | ConvertTo-Json
$jsonString

Actual output I am getting using above script:

enter image description here

>Solution :

Please try the following code; it is expected to address the problem you’re facing.

$PartnerName="testparner"
$ClientID="123-45-789"
$DM=@{
    "5903-95856-24869-e43"=@{
        "CallerName"= $PartnerName
        "ClientId"= $ClientID
        "ClientSecret"= @{
            "KeyVaultSecretName"= "ClientSecret"
        }
    }
}
$jsonData = @{
    "TestParam"= $DM
}
$jsonString = $jsonData | ConvertTo-Json -Depth 4
$jsonString
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading