I'm trying to parse Palo Alto firewall rules with Powershell. Some rules can have ~100 servernames in them. I need to break down each name to check if they're still alive (DNS) and return rule mapping for each servername. Most of it works except for:
Currently I have:
RuleName, {Hostname1;Hostname2;Hostname3}
I'm trying to get:
RuleName, Hostname1 ;
RuleName, Hostname2 ;
RuleName, Hostname3
I started with a hashtable, but having issues with overall script length - too long
I've been doing:
Select-Object RuleName,@{Name="Hostnames";Expression={($_.Hostnames).Split(";")}
But feels like I need a ForEach-Object in the Expression to add the RuleName field to each hostname, so it doesn't turn into a collection.
You need to invert your logic: enumerate the hostnames first, then construct an object for each:
Note that in this case it's simpler to use a
[pscustomobject]literal to construct the output objects, although aSelect-Objectsolution with calculated properties (as in your attempt), is possible too: