I need to go through cisco configuration files and pull specific information out to draw a Layer 3 diagram of our network. I need to pull the interface, address, vlan ID, description, etc from the configuration and arrange it in a table or excel spreadsheet. The way I am thinking of the code in my head is setting it up to somehow say "between the word vlan on line x and the next instance of the word vlan, take this information", and then adapting that for between the words interface, etc. But I'm not sure how to put that into code. I am unfortunately fairly new at powershell
example of the small part of the cisco config I'm working with. What I am trying to get out of it is vlan and number from the "vlan" line and the full name line from the line immediately under.
vlan 2
name mgmt
vlan 10
name vmotion_tools
vlan 13
name perfmontools_10.12.144.24
vlan 14
name perfmontools_10.12.145.2
etc
This is what I have so far:
foreach($line in [System.IO.File]::ReadLines('....\Config_test.txt'))
{
#look for line containing vlan
if ($line -like '*vlan*'){
$vlanid = $line
}
#look for line containing name
if ($line -like '*name*'){
$vlanname = $line
$vlanname = $vlanname -replace ".*name "
}
#look for line containing IP
if ($line -like '*ip*'){
$vlan_ip = $line
}
@{name = $vlanid; description = $vlanname} | Out-String
}
And it gives the following result:
Name Value
---- -----
name vlan 242
description perfmontools-172.xxx
Name Value
---- -----
name vlan 242
description perfmontools-172.xxx
etc
etc
etc
So they are at least grouped together correctly. I would like the name and description to appear on one line, like a table, and continue down from there. It's slow going when you don't know what you're doing :)
The end goal of this is to put all of this information into an excel spreadsheet
