troubleshooting Question

Powershell for each in Json

Avatar of Tony Cross
Tony Cross asked on
PowershellJSON
1 Comment1 Solution88 ViewsLast Modified:
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'

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'
    }
}

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
Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros