Written by 4:39 pm Hardware, Microsoft, PowerShell • 6 Comments

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
}

Tags: , , , , , , , , Last modified: January 7, 2019
Close Search Window
Close