I am trying to find an elegant way of transforming data below into collection of Powershell objects but unfortunately I am unable to find a simple way of doing it. Would someone be able to help me here?
Name: ENC1
IPv4 Address: 172.16.2.101
Link Settings: Forced, 100 Mbit, Full Duplex
Name: ENC2
IPv4 Address: 172.16.2.103
Link Settings: Forced, 100 Mbit, Full Duplex
Name: ENC3
IPv4 Address: 172.16.2.103
Link Settings: Forced, 100 Mbps, Full Duplex
Name: ENC4
IPv4 Address: 172.16.2.104
Link Settings: Forced, 100 Mbps, Full Duplex
This is what I came up with.
$out = @()
$text = Get-Content input.txt
$count = 0
do {
$line = ($text | select -Skip $count -first 3)
$obj = "" | Select Name,IP,Settings
$obj.Name = $line[0].split(":")[1]
$obj.IP = $line[1].split(":")[1]
$obj.Settings = $line[2].split(":")[1]
$out += $obj
$count = $count+3
} until ($count -eq $text.count)
$out
Is there simplier way of doing it?