Avatar of Tony Cross
Tony Cross
 asked on

Powershell for each in Json

I have a json file which has some information in as:-
$json.Hardware.'Network Adapters'.'Network Adapter 1'.'MAC Address'
$json.Hardware.'Network Adapters'.'Network Adapter 2'.'MAC Address'
$json.Hardware.'Network Adapters'.'Network Adapter 3'.'MAC Address'
$json.Hardware.'Network Adapters'.'Network Adapter 4'.'MAC Address'
$json.Hardware.'Network Adapters'.'Network Adapter 5'.'MAC Address'

Open in new window


I need to pull out the information, so thought about using a for loop:-
for ($x=1; $x -le 10; $x++) {
    if ($json.Hardware.'Network Adapters'.'Network Adapter $x'.Type -contains 'Wired*') {
        Write-Host "MAC Wired - " $json.Hardware.'Network Adapters'.'Network Adapter $x'.'MAC Address'
    }
}

Open in new window


But it isnt working. Im assuming Im not concatinating the $x in the variable name correctly, but tried to put it outside the loop as a variable, but that doesnt work.

Any ideas?
PowershellJSON

Avatar of undefined
Last Comment
oBdA

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
oBdA

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy