0

The story: I read a json configuration file and somewhere in this, i get conversion challenges.

The json file

"FwRules":[{ "IP" : "222.33.44.00/27", "Comment" : "Santa" },
           { "IP" : "223.44.11.0/24",  "Comment" : "Claus" },

Reading this file info a object gives me:

IP             Comment
--             -------
222.33.44.00/27, Santa
223.44.11.0/24, Claus

I need to get to:

222.33.44.00/27
223.44.11.0/24

As you might guess, I want to use this in

New-NetFirewallRule -RemoteAddress $HERE

However column headers need to be removed.

The obvious way

$config.smtpservers.fwrules | select-object IP 

returns what I want, but with column headers. And I really do not want to go the "foreach way", just because of OCD reasons.

So, is there a bright mind out there who can learn me how to strip of the column headers, because I cannot figure this out.

1
  • FYI, the column headers are just for display purposes and aren't actually part of the data Commented Feb 2, 2021 at 0:28

1 Answer 1

1

This should do the trick:

$config.smtpservers.fwrules.ip

With dot syntax, Powershell automatically builds an array from properties that exist for each array element.

Alternatively:

$config.smtpservers.fwrules | select-object -ExpandProperty IP
Sign up to request clarification or add additional context in comments.

1 Comment

THANKS!!! You saved me a lot of frustration. I guess this is one of those days where the head just doesn't work...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.