Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Add multiple instances of a noteproperty to an object

$
0
0

It sounds like what you want is an object that has a string property (site name), and an array property (Subnets). Anytime you find yourself creating properties or variables named Thingy1, Thingy2, etc, it’s a sure sign that you should actually be dealing with some sort of array or collection. You can also shorten the code quite a bit by making use of Group-Object, instead of reinventing that particular wheel yourself with the nested loop:

$sites = Import-Csv -Delimiter ";" .\AdSitestoSubnets.csv

$unique_sites = $sites |
Group-Object -Property Site |
Select-Object -Property @(
    @{ Name = 'Site';    Expression = { $_.Name } }
    @{ Name = 'Subnets'; Expression = { $_.Group | Select-Object -ExpandProperty Subnet } }
)

Viewing all articles
Browse latest Browse all 13067

Trending Articles