Hi.
I have output like this from a Cisco switch that I try to convert to Objects:
switch01#show interfaces counters errors
Port Align-Err FCS-Err Xmit-Err Rcv-Err UnderSize OutDiscards
Gi0/1 0 0 0 0 0 0
Gi0/2 0 0 0 0 0 0
Gi0/3 0 0 0 0 0 125
Gi0/4 0 0 0 0 0 0
Gi0/5 0 0 0 0 0 0
Gi0/6 0 0 0 0 0 409
Gi0/7 0 0 0 0 0 0
Gi0/8 0 0 0 0 0 0
Port Single-Col Multi-Col Late-Col Excess-Col Carri-Sen Runts Giants
Gi0/1 0 0 0 0 0 0 0
Gi0/2 0 0 0 0 0 0 0
Gi0/3 30 60 0 1 0 0 0
Gi0/4 0 0 0 0 0 0 0
Gi0/5 0 0 0 0 0 0 0
Gi0/6 0 0 0 0 0 0 0
Gi0/7 0 0 0 0 0 0 0
Gi0/8 0 0 0 0 0 0 0
switch01#
I try to process the text like this:
$PortFil = ‘C:\data\ScriptLAB\SwitchType_C2960G_8port.txt’
$Ports = Get-Content $PortFil
$SWPorts = $Ports | Select-Object -Skip 2 | Select-Object -first($Ports.length - 3)
$CSVports = ConvertFrom-Csv $SWPorts
My main problem is that the output from the switch is split up into 2(or more depending on switch type) blocks of text.
I’d like to created Objects With names from the “Port” column, and Properties with PropertyName from the HeaderRow(s), and values from the corresponding rows in all the columns including columns in the following Block(s).
Can ConvertFrom-Csv do this, or do I have to revert to reading line by line and constructing the Objects based on
the content of each line?
Regards Geir