Link to home
Create AccountLog in
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?
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account