question

mojo27-0587 avatar image
0 Votes"
mojo27-0587 asked mojo27-0587 edited

Loop to iterate through JSON

[
{
"RgName": "DOTcom-dev-rg",
"Name": "dev",
"AppName": "devse-cd"
},
{
"RgName": "DOTcom-dev-rg",
"Name": "dev-cm",
"AppName": "devse-cm"
},
{
"RgName": "DOTcom-uat-rg",
"Name": "uat",
"AppName": "uatse-cd"
},
{
"RgName": "DOTcom-uat-rg",
"Name": "uat-cm",
"AppName": "uatse-cm"
}
]

windows-server-powershell
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Show us the code you are running and what error you are getting.

0 Votes 0 ·

1 Answer

IanXue-MSFT avatar image
0 Votes"
IanXue-MSFT answered mojo27-0587 commented

Hi,

You can first read the json file and convert it to a PSCustomObject.

 $file = 'd:\temp\file.json'
 $contents = Get-Content -Path $file | ConvertFrom-Json 

To get the items with specified property value you can use "Where-Object".

 $contents | Where-Object {$_.RGname -eq 'DOTcom-dev-rg'}

Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you, will try with this.

0 Votes 0 ·