, ,

Create Cisco VLAN Config with Powershell

1–2 minutes
6 comments on Create Cisco VLAN Config with Powershell

Powershell HeaderSmall Script for creating a simple CISCO VLAN config.

# Create Cisco VLANs Config
#
# www.thomasmaurer.ch
# (c) 2010 Thomas Maurer
#
#

# First VLAN which should be created?
[int]$VLAN = 1201
# How many VLANs should be created?
[int]$VLANCount = 25
# Start IP Address
[int]$IP = 1
# Subnet
[string]$Subnetmaskv4 = "255.255.255.252"
[string]$Subnetmaskv6 = "64"
# Next IP (Its Important for Subnet)
[int]$AddtoIP = 4
# IPv4 Address Template
[string]$IPv4AddressTemplate = "192.168.1."
# IPv6 Address Template
[string]$IPv6AddressTemplate = "2002:1b50:251:22:192:168:1:"
# Config File Name
[String]$ConfigFile = "C:\Users\tm\Desktop\config.txt"

# Creats Config
for($counter = 0;$counter -le $VLANCount;$counter++) {
[string]$interfaceconf = "interface Vlan" + $VLAN
[string]$IPv4conf = "ip address " + $IPv4AddressTemplate + $IP + " " + $Subnetmaskv4
[string]$IPv6conf = "ipv6 address " + $IPv6AddressTemplate + $IP + "/" + $Subnetmaskv6
Add-Content $ConfigFile $interfaceconf
Add-Content $ConfigFile "no shutdown"
Add-Content $ConfigFile $IPv4conf
Add-Content $ConfigFile $IPv6conf
$IP = $IP + $AddtoIP
}

6 responses

  1. Paul Wonnell Avatar
    Paul Wonnell

    New to Powershell – just recently inherited a network of Cisco switches and want to ssh to each switch down load to running configs, startup and do a show ver. Have you done anything like this? I know there are a many tools that will do this, but $ are scarce here so I have to use what I have.

  2. Paul Wonnell Avatar
    Paul Wonnell

    New to Powershell – just recently inherited a network of Cisco switches and want to ssh to each switch down load to running configs, startup and do a show ver. Have you done anything like this? I know there are a many tools that will do this, but $ are scarce here so I have to use what I have.

  3. Thomas Maurer Avatar

    Hi Paul

    I never done exactly this before, but I did some other scripts which did automatically connect to other servers via ssh using putty. Basically you could run a powershell script which connects to the switches via putty and runs an other (IOS) script which does what ever you want on your switch.

  4. Thomas Maurer Avatar

    Hi Paul

    I never done exactly this before, but I did some other scripts which did automatically connect to other servers via ssh using putty. Basically you could run a powershell script which connects to the switches via putty and runs an other (IOS) script which does what ever you want on your switch.

  5. Dan Avatar

    Interesting script. Were you intending to create 26 subnets, all tagged 1201?

    1. Thomas Maurer Avatar

      It’s a old post but this could be a mistake :)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.