Hi there people!
I have some trouble looping through these domains.
What I’m trying to do is to scan for a specific value, in this test an ID, inside this JSON file, and notifying me when it is found.
The structure, is somewhat different than what i usually see, and i cant seem to figure out how to make PowerShell identify the sub-sections containing the data i need, as objects.
I feel that I’m missing a header to target?
This is the JSON structure:
{
"2": {
"id": "2",
"url": "https://tester774.com/",
"name": "apktest.dk"
},
"7": {
"id": "7",
"url": "https://tester223.com/",
"name": "introtest.dk"
},
"17": {
"id": "17",
"url": "https://tester92.com/",
"name": "sectest.dk"
},
"4667": {
"id": "4667",
"url": "https://tester432.com/",
"name": "mnitest.dk"
},
"4668": {
"id": "4668",
"url": "https://tester112.com/",
"name": "kptest.dk"
}
This is the script i am testing with:
$jsondata = Invoke-WebRequest -Uri $jsonurl -Method GET
$jsondata | ConvertFrom-Json
$jsondata | ForEach-Object {
write-host "This is ID:" $_.id "- This is URL:"$_.url "- This is Name:" $_.name
if ($_.id -like "*17*") {
write-host "Number 17 found!"
write-host "This is URL:"$_.url "- This is Name:" $_.name
}
else {
write-host "we did not find ID 17"
}
}
This does list all the individual objects, in the terminal (using PS 7.2 with Visual Studio Code)
( if i remove the foreach-object loop that does not work anyways).
Looking like this:
4437 : @{id=2; url=https://tester774.com/; name=apktest.dk}
3508 : @{id=7; url=https://tester223.com/; name=introtest.dk}
So, i do have access to all these sections, i just cant figure out how to “grab” the data from them in a loop. I figured they need to be individually "ConvertFrom-Json"ed, but how do i target them?
Please help!
Best regards
Jonatan